Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the StatuteCode node below, I would like to check if the first 3 characters are not equal to 169.

XML
<StatuteCode Word="169142a4">Running</StatuteCode>


How do I do it using xslt choose?

What I have tried. I think this is wrong.

What I have tried:

XML
<xsl:choose>
	<xsl:when test='(StatuteCode,1,4)="169")'>
		<xsl:value-of select="true()"/>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="false()"/>
	</xsl:otherwise>
</xsl:choose>
Posted
Updated 7-Aug-18 8:18am
v2

1 solution

Try:
XML
<xsl:choose>
    <xsl:when test="starts-with(StatuteCode, '169')">
        <xsl:value-of select="true()"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="false()"/>
    </xsl:otherwise>
</xsl:choose>

starts-with - XPath | MDN[^]
 
Share this answer
 
Comments
Member 11403304 7-Aug-18 14:04pm    
What would be the path if the node was like this?
<charge><chargehistory><statute><StatuteCode Word="269142a4">Traffic
Richard Deeming 7-Aug-18 14:13pm    
In the context of the <statue> element:
<xsl:when test="starts-with(StatuteCode/@Word, '169')">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900