4

I have a XML like this

<extra>
    <name>format-xml</name>
    <value>excel.xls</value>
</extra>
<extra>
    <name>format-java</name>
    <value>hello.java</value>
</extra>
<extra>
    <name>Date</name>
    <value>someday</value>
</extra>
<extra>
    <name>version</name>
    <value>2</value>
</extra>

I would like to use XSLT to get he foamt-* name

I try the start-with, but it doesn't work

<xsl:for-each select="extra[starts-with(name(),'format-')]">
    Format name:  <xsl:apply-templates select="name" />
    Format value:  <xsl:apply-templates select="value" />           
</xsl:for-each>
cc96ai
  • 653
  • 4
  • 14
  • 23

1 Answers1

9

name() will give you the name of the context node (which in your example is <extra>). You are trying to match on the <name> element's value.

Adjust your select statement to:

extra[starts-with(name,'format-')]
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147