Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select the element which match the start-with name

Tags:

xslt

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>
like image 579
cc96ai Avatar asked Jan 20 '23 09:01

cc96ai


1 Answers

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-')]
like image 56
Mads Hansen Avatar answered Jan 28 '23 07:01

Mads Hansen