i have xml file follows,
<sec> <para>section 1- toc</para> <para>section 4* main</para> <para>section 3$ basic content</para> <para>section 11_ section 10</para> <para>section 15@ appendix 6</para> </sec>
i need number followed 'section' string in text()
node using function.
example:
<xsl:function name="abc:get-section-number"> <xsl:param name="string" as="xs:string"/> <xsl:sequence select="tokenize($string,'\d+')[1]"/> </xsl:function>
this example returns substring before number value need number value after 'section' string.. (output values should 1,4,3,11 , 15)
i tried in-build functions (string-before, strong-after, matches..) couldn't find proper solution.
can suggest me method number value?
you can use analyze-string
, suggested in comment, see http://xsltransform.net/3nj38zy working sample does
<?xml version="1.0" encoding="utf-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:abc="http://example.com/abc" exclude-result-prefixes="xs abc"> <xsl:function name="abc:get-section-number" as="xs:integer"> <xsl:param name="string" as="xs:string"/> <xsl:analyze-string select="$string" regex="^section\s+([0-9]+)"> <xsl:matching-substring> <xsl:sequence select="xs:integer(regex-group(1))"/> </xsl:matching-substring> </xsl:analyze-string> </xsl:function> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="para"> <xsl:copy> <xsl:value-of select="abc:get-section-number(.)"/> </xsl:copy> </xsl:template> </xsl:transform>
Comments
Post a Comment