I am trying to use analyze-string on elements that possibly contain children nodes. Here is a snippet of a source file:
<year>
1975 music
</year>
<year>
1985<genre>rock</genre>music
</year>
<year>
2005 music
</year>
And here is what I would like to get:
<year>
70's music
</year>
<year>
80's<genre>rock</genre> music
</year>
The following code correctly matches the 3 cases, but I am missing something to copy both the text and the possible children nodes under the year element:
<xsl:template match="year">
<xsl:variable name="item" select="."/>
<xsl:analyze-string select="." regex="19(\d)\d">
<xsl:matching-substring>
<xsl:variable name="decade">
<xsl:value-of select="concat(regex-group(1),'0''s')"/>
</xsl:variable>
<year>
<xsl:value-of select="concat($decade,regex-group(2))"/>
<genre><xsl:value-of select="$item/genre"/>
</genre>
</year>
</xsl:matching-substring>
<xsl:non-matching-substring> </xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
Here is what I get:
<year>70's<genre/></year>
<year>80's<genre>rock</genre></year>
Thanks in advance for any help!