Select the item that matches the starting name.

I have such XML

<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 it foam - the name

I'm trying to 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> 
+4
source share
1 answer

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

Adjust your selection statement:

 extra[starts-with(name,'format-')] 
+9
source

Source: https://habr.com/ru/post/1341461/


All Articles