I'm working on XML-to-XML transformation (Windows 10, Oxygen XML Editor) and got this task: replace <xref id="id1">text</xref> with id1.
I've done some work but can't get why doesn't scenario replace all xref-s in parentheses. Any ideas?
And just in case if somebody know how to remove parentheses outside of xref-s, please tell. I was trying concat('(',$temp,')') but it also skips parenteses and concat('(',$temp,';') even doesn't work.
Here the example (I keep punctuation just in case):
<section> <somenode>Lorem ipsum</somenode> <p>Lorem ipsum (<xref id="id1">TEXT1, 2014</xref>) dolor.</p> <p>Lorem ipsum (<xref id="id5">TEXT5., 2016</xref>) dolor.</p> <p>Lorem ipsum (<xref id="id6">TEXT6., 2004</xref>; <xref id="id7">TEXT7., 2014</xref>; <xref id="id8">TEXT8., 2012</xref>), dolor.</p> <p>Lorem ipsum (<xref id="id6">TEXT6., 2004</xref>; <xref id="id7">TEXT7., 2014</xref>; <xref id="id8">TEXT8., 2012</xref>), dolor.</p> ... <section> ... Here the result:
<section> <somenode>Lorem ipsum</somenode> Lorem ipsum (id1) dolor. Lorem ipsum (id5) dolor.</p> Lorem ipsum (id6; TEXT7., 2014; TEXT8., 2012), dolor. Lorem ipsum (TEXT6., 2004; id7; TEXT8., 2012), dolor. ... <section> ... and Here the scenario:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xml" encoding="UTF-8"/> <xsl:template name="xrefs"> <xsl:for-each select="section"> <xsl:for-each select="p"> <xsl:variable name="tempP"> <xsl:value-of select="."/> </xsl:variable> <xsl:for-each select="xref"> <xsl:variable name="temp"> <xsl:value-of select="."/> </xsl:variable> <xsl:value-of select="replace($tempP,$temp,./@id)"/> </xsl:for-each> </xsl:for-each> </xsl:for-each> </xsl:template> <xsl:template match="/"> <xsl:call-template name="xrefs"/> </xsl:template>
No comments:
Post a Comment