I'm trying to create an xsl template that will accept wildcards as part of the template match as the following example will show:
<xsl:template match="*_Nokia_5.0">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
<xsl:if test="position()=last()">
<xsl:text> </xsl:text>
</xsl:if>
What I'm trying to achieve is 'match any tag that has 'Nokia_5.0' as part of the string. Is there any way I can do this in xslt 1.0?
Thanks
Using contains(name(), "Nokia_5.0") is not the solution, as it will return false positives on names like:
myNokia_5.0isAwsome
however the requirement is that the name must end with the string 'Nokia_5.0'.
A correct solution:
In XSLT 2.0:
<xsl:template match="*[ends-with(name(), 'Nokia_5.0')]">
In XSLT 1.0:
<xsl:template match=
"*[substring(name(), string-length(name()) -8) = 'Nokia_5.0')]">
Assuming you mean the node name must contain the given string, you can use contains()
<xsl:template match='*[contains(name(), "Nokia_5.0")]'>
However this would mean that any nodes that DON'T conform to this requirement lack a template, and would be output as-is if you applied templates to all nodes.
Instead, you could make the filter stipulation not in the template definition but at the point of applying templates.
<xsl:apply-templates select='node[contains(name(), "Nokia_5.0")]' />
....
<xsl:template match='node'>
<xsl:value-of select='.' />
</xsl:template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With