Subject: RE: [xsl] Converting markup to non-markup From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Thu, 12 Sep 2002 15:58:12 +0100 |
With Saxon 7.2 you can do <CONVERTED_TAG> <xsl:value-of select="saxon:serialize(TAG1, 'xml')"/> </CONVERTED_TAG> Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Lars Eskildsen > Sent: 12 September 2002 14:03 > To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx' > Subject: [xsl] Converting markup to non-markup > > > 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><xs > l: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 > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Converting markup to non-, Mike Brown | Thread | RE: [xsl] Converting markup to non-, Satish, L. Gnanendra |
Re: [xsl] xsl:fo - keeps and breaks, Jeni Tennison | Date | [xsl] document() loops, Laura Jenkins |
Month |