tags:

views:

421

answers:

2

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

enter code here ID    FNAME
                 1    AA
                 2    BB

XML:

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

XSLT so far: I have traverse upto studentDetails and then

enter code here <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  A: 

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]"/>
Dewfy
At first don't pass "'id'" just use "id" At second = pattern * selects node----sorry didnt get u, can u pls explain a bit.
Wondering
it worked.thanks.
Wondering
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::* = @*
Dewfy
+2  A: 

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.

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