Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
XML
XLST2 and stringmanipulation
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Martin Honnen, post: 776377"] Andreas Kraftl wrote: I don't really understand on which node you want to apply templates but it doesn't work as Saxon rightly tells you that the context item inside the matching-substring instruction is an atomic value, it is a string value resulting from the regular expression match. Using the following "dictionary" <?xml version="1.0" encoding="UTF-8"?> <lexikon> <begriff> <synonyme> <synonym>a</synonym> <synonym>b c</synonym> </synonyme> <beschreibung> Tolle Buchstaben. </beschreibung> </begriff> </lexikon> and the following XML input <?xml version="1.0" encoding="UTF-8"?> <text>Da ist ein b c und da ein a</text> the following XSLT 2.0 stylesheet <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="[URL]http://www.w3.org/1999/XSL/Transform[/URL]"> <xsl:output method="xml" encoding="UTF-8" /> <xsl:variable name="lexwordstring"> <xsl:text>(</xsl:text> <xsl:for-each select="document('test2004121801.xml')/lexikon/begriff/synonyme/*"> <xsl:value-of select="normalize-space(.)"/> <xsl:if test="position() != last()"> <xsl:text>|</xsl:text> </xsl:if> </xsl:for-each> <xsl:text>)</xsl:text> </xsl:variable> <xsl:template match="text()"> <xsl:analyze-string select="." regex="{$lexwordstring}"> <xsl:matching-substring> <a href="" class="lexikon"> <xsl:value-of select="regex-group(1)"/> <span> <xsl:value-of select="document('test2004121801.xml')/lexikon/begriff[synonyme/synonym = regex-group(1)]/beschreibung" /> </span> </a> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates /> </xsl:copy> </xsl:template> </xsl:stylesheet> outputs <?xml version="1.0" encoding="UTF-8"?><text>D<a href="" class="lexikon">a<span> Tolle Buchstaben. </span></a> ist ein <a href="" class="lexikon">b c<span> Tolle Buchstaben. </span></a> und d<a href="" class="lexikon">a<span> Tolle Buchstaben. </span></a> ein <a href="" class="lexikon">a<span> Tolle Buchstaben. </span></a></text> with Saxon 8.1.1, maybe that helps you to find a solution. I realize that more characters are matched than you are looking for (e.g. the 'a' in 'Da'), I have tried to remedy that with using \b in the regular expression but unfortunately it seems the regular expression syntax in XSLT 2.0/XPath 2.0 doesn't know \b (word boundary). [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
XML
XLST2 and stringmanipulation
Top