Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 247961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:18:11+00:00 2026-05-11T21:18:11+00:00

Please review my code and give me your advise on this: XML file: content.xml

  • 0

Please review my code and give me your advise on this:

XML file: content.xml:

<content>
<page id="page-1">
<!-- ... -->
<block-center>
  <block-center-row id="block-center-row-1">
    <cd>
      <title>Empire Burlesque</title>
      <artist>Bob Dylan</artist>
      <country>USA</country>
      <company>Columbia</company>
      <price>10.90</price>
      <year>1985</year>
    </cd>
    <cd>
      <title>Hide your heart</title>
      <artist>Bonnie Tyler</artist>
      <country>UK</country>
      <company>CBS Records</company>
      <price>9.90</price>
      <year>1988</year>
    </cd>
  </block-center-row>
  <block-center-row id="block-center-row-2">
    <block-center-colunm id="block-center-2-1">
      <book>
        <title>Book Title1</title>
        <author>Book Author1</author>
      </book>
      <book>
        <title>Book Title2</title>
        <author>Book Author2</author>
      </book>
      <book>
        <title>Book Title3</title>
        <author>Book Author3</author>
      </book>
    </block-center-colunm>
    <block-center-colunm id="block-center-2-2">
      <seminar>
        <author>Seminar author1</author>
        <durable>3</durable>
      </seminar>
      <seminar>
        <author>Seminar author2</author>
        <durable>1.5</durable>
      </seminar>
      <seminar>
        <author>Seminar author3</author>
        <durable>2</durable>
      </seminar>
      <seminar>
        <author>Seminar author4</author>
        <durable>3</durable>
      </seminar>
    </block-center-colunm>
  </block-center-row>
</block-center>
</page>
<!-- ... -->
</content>

XSL file: block-center-1-1.xsl:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template name="block-center-row-1">
    <div class="block-center-row">
      <h2>My CD Collection</h2>
      <table border="1" width="100%">
        <tr bgcolor="#9acd32">
          <th>Title</th>
          <th>Artist</th>
        </tr>
        <xsl:for-each select="
          content/page[@id=$pageId]/block-center/
          block-center-row[@id='block-center-row-1']/cd
        ">
          <tr>
            <td>
              <xsl:value-of select="title" />
            </td>
            <xsl:choose>
              <xsl:when test="price &gt; 10">
                <td bgcolor="#ff00ff">
                  <xsl:value-of select="artist" />
                </td>
              </xsl:when>
              <xsl:when test="price &gt; 9">
                <td bgcolor="#cccccc">
                  <xsl:value-of select="artist" />
                </td>
              </xsl:when>
              <xsl:otherwise>
                <td>
                  <xsl:value-of select="artist" />
                </td>
              </xsl:otherwise>
            </xsl:choose>
          </tr>
        </xsl:for-each>
      </table>
    </div>
  </xsl:template>
</xsl:stylesheet>

XSL file block-center.xsl:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="block-center-1-1.xsl" />
  <xsl:template name="block-center">
    <!-- if put here. It work properly -->
    <div class="block-center"> 
      <xsl:for-each select="content/page[@id=$pageId]/block-center/block-center-row">
        <xsl:choose>
          <!-- // I does not work here --> 
          <xsl:when test="@id='block-center-row-1'">
            <xsl:call-template name="block-center-row-1" />
          </xsl:when>
        </xsl:choose>
      </xsl:for-each>
    </div>
  </xsl:template>
</xsl:stylesheet>

I dont know why It does not work (not out put data) if I call <xsl:call-template> inside <xsl:for-each> loop. Otherwise, It’s OK.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:18:11+00:00Added an answer on May 11, 2026 at 9:18 pm

    I have a few remarks to make. First off, it is a bad idea to make format implications in the XML. Having elements that are called <block-center> or <block-center-colunm> is not only unnecessarily verbose, it will also make your head hurt as soon as their contents is not going to be displayed in a block in the center anymore.

    Second, let go of <xsl:call-template> and <xsl:for-each>. They may seem convenient if you have procedural programming background, but they are the wrong choice. Use <xsl:apply-templates> instead, it leads to code that’s cleaner and easier to understand.

    Now to your XSL. Your second XSL (block-center.xsl) – what does it do? Why do you have two separate XSL files? Also, it is missing a variable or parameter declaration. I’ve used:

    <xsl:variable name="pageId" select="'page-1'" />
    

    for my tests. It also has only one template (<xsl:template name="block-center">) that is never actually being called, so it did not do anything for me. I’ve added

    <xsl:template match="/">
      <xsl:call-template name="block-center" />
    </xsl:template>
    

    so it would at least do anything.

    Your other XSL file (block-center-1-1.xsl) has a for-each loop that is not looking at the right context. You already are in the following context when you enter the template "block-center-row-1“:

    content/page[@id=$pageId]/block-center/block-center-row
    

    so all you need to do in the for-each loop is:

    <xsl:for-each select="cd">
    

    and it will start to output all <cd> nodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would someone please review this code and tell me why the for loops are
Please, provide code examples in a language of your choice. Update : No constraints
Please review my code. For every my Entity i've created a service class, where
I got another problem with the FCKEditor within ASP.NET MVC. Please review the code
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please give me the direction of the best guidance on the Entity Framework.
Please excuse the vague title. If anyone has a suggestion, please let me know!
Please provide tips for effectively using git with svn. What are your best practices?
The code public partial class Table_Traversing : System.Web.UI.Page { Table table1 = new Table();
Please suggest some good resources to start writing Java Web services.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.