I have an XML file that I need to transform using an XSL script.
Below is an example feed. I need to extract the text in the NameLabel
element, but I only need the text specifically between the first two dashes.
For example, I want the A
in the string below:
NTX-A-20120131-0006
I'm not well versed in XPath, so I'm struggling to put together an expression, however I'm assuming I need to use substring-(after|before). I'm just not sure how.
Sample XML:
<NewsML>
<NewsItem>
<Identification>
<NameLabel>NTX-A-20120131-0006</NameLabel>
</Identification>
</NewsItem>
</NewsML>
Edit:
I am using xslt 1.0
substring-before(s1,s2) and substring-after(s1,s2) would work.
substring-before(substring-after(NewsML/NewsItem/Identification/NameLabel,'-'),'-')
try
<xsl:template match="/">
<xsl:apply-templates select="NewsItem/NewsML/Identification"/>
</xsl:template>
<xsl:template match="Identification">
<xsl:value-of select="substring-before(substring-after(NameLabel,'-'),'-'))"/>
</xsl:template>
but i couldn't test this
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