Subject: [xsl] Converting markup to non-markup From: Lars Eskildsen <laes@xxxxxxxxx> Date: Thu, 12 Sep 2002 15:02:58 +0200 |
Hello! I want to be able to convert an XML snippet like: <CONV_TAG> <TAG1 ATTR1="VAL1">Statement: 4 < 5</TAG1> <CONV_TAG> to this XML code: <CONVERTED_TAG> <TAG1 ATTR1="VAL1">Statement: 4 &lt; 5</TAG1> </CONVERTED_TAG> I have no problem with the "entifying" of the original markup - i use the XSL templates below) ---------------------------- <xsl:template match="node()" mode="xml-to-text"><<xsl:value-of select="name()"/><xsl:apply-templates select="@*" mode="xml-to-text"/>><xsl:apply-templates select="node()" mode="xml-to-text"/></<xsl:value-of select="name()"/>></xsl:template> <xsl:template match="@*" mode="xml-to-text"><xsl:text> </xsl:text><xsl:value-of select="name()"/>=<xsl:text disable-output-escaping="yes"><![CDATA["]]></xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes"><![CDATA["]]> </xsl:text></xsl:template> <xsl:template match="text()" mode="xml-to-text"><xsl:value-of select="."/></xsl:template> --------------------------- The problem is i want to convert standard entities inside non-markup content. < to <lt; > to >gt; & to &amp; ...and so on. I therefore changed the third rule (in the above) which is the one that deals with non-markup content, to the following two templates: -------------------------------------- <xsl:template match="text()" mode="xml-to-text"> <xsl:variable name="NodeText"><xsl:value-of select="normalize-space(.)"/></xsl:variable> <xsl:call-template name="Entify"> <xsl:with-param name="TheText" select="$NodeText"> </xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="Entify"> <xsl:variable name="TheText"><xsl:value-of select="'AAA'"/></xsl:variable> <xsl:choose> <xsl:when test="substring-before($TheText, '<')"> <xsl:value-of select="concat(substring-before($TheText, '<'), '<lt')"/> <xsl<xsl:value-of select="substring-after($TheText, '<')"/> </xsl:with-param>ame="TheText"> </xsl:call-template> </xsl:when> <xsl:when test="substring-before($TheText, '>')"> <xsl:value-of select="concat(substring-before($TheText, '<'), '>gt;')"/> <xsl:call-template name="Entify"> <x<xsl:value-of select="substring-after($TheText, '>')"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:when test="substring-before($TheText, '&')"> <xsl:value-of select="concat(substring-before($TheText, '&'), '&amp;')"/> <xsl:call-template name="Entify"> <x<xsl:value-of select="substring-after($TheText, '&')"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$TheText"/> </xsl:otherwise> </xsl:choose> </xsl:template> ----------------------------------------------------- The problem is that the macro template variable/parameter TheText always seems to be undefined in connection with the template macro call and therefore receive the value 'AAA' inside the macro template. Then all my non-markup content is converted to 'AAA' ! What is wrong with this approach - can anybody please help me!! /Lars ** Stibo Graphic | Søren Nymarks Vej 21 | DK-8270 Højbjerg ** mailto:laes@xxxxxxxxx | http://www.stibographic.com ** Phone: +45 8939 8939 | Fax: +45 8939 8940 ** Direct: +45 8939 7421 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Dynamic include, Dimitre Novatchev | Thread | Re: [xsl] Converting markup to non-, Mike Brown |
Re: Re: [xsl] Getting desired node , alex ek | Date | AW: [xsl] using global variables in, Felix, Peter |
Month |