3

Here is a bit of XML that's in each record:

<MT N="usage" V="something"/>
<MT N="usage" V="something else"/>

I'm trying to display all of these V values for each record with XSLT, but am having issues targeting the correct value.

<xsl:for-each select="MT[@N = 'usage']/@V">
    <xsl:value-of select="V"/>
    11
</xsl:for-each>

This outputs "1111", but the value of V isn't displayed. How do I target that?

Cheers

Cory Dee
  • 2,858
  • 6
  • 40
  • 55

2 Answers2

6

select="V" probably is not a node.

What about

<xsl:for-each select="MT[@N = 'practice']">
<xsl:value-of select="@V"/>
11
</xsl:for-each>
FailedDev
  • 26,680
  • 9
  • 53
  • 73
1
<xsl:for-each select="MT[@N = 'usage']/@V"> 
    <xsl:value-of select="V"/> 
    11 
</xsl:for-each>

The <xsl:value-of> above is trying to display the value of an element V that is a child of the current node. However the current node is an attribute, and attributes by definition have no children. This is the problem that you have.

Solution:

<xsl:for-each select="MT[@N = 'usage']/@V"> 
    <xsl:value-of select="."/> 
    11 
</xsl:for-each>

Now the <xsl:value-of> outputs the string value of the current node -- which was probably intended.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431