Project

Profile

Help

XSLT2 Stringmanipulation

Added by Anonymous almost 20 years ago

Legacy ID: #2903250 Legacy Poster: Andreas Kraftl (akraftl)

Hello, i've a xml file: <lexikon> <begriff> <synonyme> <synonym>a</synonym> <synonym>b c</synonym> </synonym> <beschreibung> <b>G</b>reat letters. </beschreibung> </begriff> ... </lexikon> Then there is an other XML file where i would every string from <synonym> extending. Example XML file: There is an b c and there an a should be extend to There is an <a href="lexikon.php" class="lexikon">b c<span> <strong>G</strong>reat letters.</span></a> and there an <a href="lexikon.php" class="lexikon">a<span> <strong>G</strong>reat letters.</span></a> Following works not: <!-- build the regex string --> <xsl:variable name="lexwordstring"> <xsl:text>(.?)(</xsl:text> <xsl:for-each select="/pages/page/content/lexikon/begriff/synonyme/"> <xsl:text>|</xsl:text> <xsl:value-of select="normalize-space(.)"/> </xsl:for-each> <xsl:text>)([ ,.]*?)</xsl:text> </xsl:variable> <xsl:template match="text()"> <xsl:analyze-string select="." regex="{$lexwordstring}"> <xsl:matching-substring> <xsl:value-of select="regex-group(1)"/> <a href="{$lexikonpage}" class="lexikon"> <xsl:value-of select="regex-group(2)"/> <span> <xsl:apply-templates select="document('lexikon.xml')/lexikon/begriff[synonyme/synonym = regex-group(2)]/beschreibung"/> </span> </a> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> Saxon means with <xsl:apply-templates> "Cannot select a node here: the context item is an atomic value" Without <xsl:apply-templates>, it works, but without the description ;). I need <apply-templates> for childrens. Any idea? Thanks Andy


Replies (2)

RE: XSLT2 Stringmanipulation - Added by Anonymous almost 20 years ago

Legacy ID: #2905979 Legacy Poster: Michael Kay (mhkay)

I can't see how the code you've shown would produce this error. Can you provide a complete stylesheet that shows the problem, so I can try and reproduce it? You might also try and see whether it still fails on the new Saxon 8.2 release. You do need to be careful calling apply-templates in this context, because you can't use any expressions that depend on the context node, but your path expression starting with a call on document() doesn't appear to have such a dependency. Michael Kay Saxonica Limited

RE: XSLT2 Stringmanipulation - Added by Anonymous almost 20 years ago

Legacy ID: #2909690 Legacy Poster: Andreas Kraftl (akraftl)

> you can't use any expressions that depend on > the context node Thanks a lot. You show me the right way. Now it works perfectly. And also thanks for your great books and of course saxon :-). Greetings from Vienna Andy

    (1-2/2)

    Please register to reply