1

I have to create one table using XSLT and CSS. The table should look like

                ID    FNAME
                 1    AA
                 2    BB

XML:

<students>
    <studentDetails  id="1" fname="AA"/>
    <studentDetails  id="2" fname="BB"/>
</students>

XSLT so far: I have traverse upto studentDetails and then

<td >
      <xsl:call-template name="zz">
      <xsl:with-param name="child-name" select="'id'"/>
      </xsl:call-template>
    </td>
     <xsl:template name="zz">
<xsl:param name="child-name"/>

<xsl:value-of select="*[name(@id) = $child-name]"/>//should print 1 and then 2 in next row

Can somebody suggest where i am going wrong?

2 Answers 2

5

At first don't pass "'id'" just use "id" At second = pattern * selects node, but you need attr (@*), so you need write:

<xsl:value-of select="@*[name()=$child-name]"/>
Sign up to request clarification or add additional context in comments.

2 Comments

At first don't pass "'id'" just use "id" At second = pattern * selects node----sorry didnt get u, can u pls explain a bit.
students, studentDetails -it is elements, when you write XPath expression to code any of them you need use ''. id, fname are attributes to get to them use over XPath over '@' Instead of * or @* you can specify axes (see hacker response) attribute::* = @*
2

try

<xsl:value-of select="attribute::*[name() = $child-name]"/>

instead.

Edit: I have just read through Dewfy's answer. This is equivalent to what he proposed. Except for his "at first" part is an alternative to this, not something you have to in addition to changing xsl:value-of.

2 Comments

whats the difference between <xsl:value-of select="@*[name()=$child-name]"/> and <xsl:value-of select="attribute::*[name() = $child-name]"/>
Wondering - none ;-) It's just that after reading the first sentence I assumed he's talking about different approach instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.