[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting markup to non-markup

Subject: RE: Converting markup to non-markup
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 12 Sep 2002 15:58:12 +0100
xsl convert amp
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:  Converting markup to non-markup
> 
> 
> Hello!
> 
> I want to be able to convert an XML snippet like:
> 
> <CONV_TAG>
>     <TAG1 ATTR1="VAL1">Statement: 4 &lt; 5</TAG1>
> <CONV_TAG>
> 
> to this XML code:
> 
> <CONVERTED_TAG>
>    &lt;TAG1 ATTR1=&quot;VAL1&quot;&gt;Statement: 4 &amp;lt; 
> 5&lt;/TAG1&gt; </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">&lt;<xsl:value-of 
> select="name()"/><xsl:apply-templates select="@*" 
> mode="xml-to-text"/>&gt;<xsl:apply-templates select="node()" 
> mode="xml-to-text"/>&lt;/<xsl:value-of 
> select="name()"/>&gt;</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[&quot;]]></xsl:text><xs
> l:value-of
> select="."/><xsl:text 
> disable-output-escaping="yes"><![CDATA[&quot;]]> 
> </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. 
> 
> &lt;	to 	&lt;lt;
> &gt;	to 	&gt;gt;
> &amp;	to	&amp;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, '&lt;')">
>         <xsl:value-of 
> select="concat(substring-before($TheText, '&lt;'), '&lt;lt')"/>
>         <xsl<xsl:value-of select="substring-after($TheText, '&lt;')"/>
>           </xsl:with-param>ame="TheText">
>         </xsl:call-template>
>      </xsl:when>
>      <xsl:when test="substring-before($TheText, '&gt;')">
>         <xsl:value-of 
> select="concat(substring-before($TheText, '&lt;'), '&gt;gt;')"/>
>         <xsl:call-template name="Entify">
>           <x<xsl:value-of select="substring-after($TheText, '&gt;')"/>
>           </xsl:with-param>
>         </xsl:call-template>
>      </xsl:when>
>      <xsl:when test="substring-before($TheText, '&amp;')">
>         <xsl:value-of 
> select="concat(substring-before($TheText, '&amp;'), '&amp;amp;')"/>
>         <xsl:call-template name="Entify">
>           <x<xsl:value-of select="substring-after($TheText, 
> '&amp;')"/>
>           </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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.