This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Converting markup to non-markup


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@ntlworld.com
work: Michael.Kay@softwareag.com 

> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com 
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of 
> Lars Eskildsen
> Sent: 12 September 2002 14:03
> To: 'XSL-List@lists.mulberrytech.com'
> 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 &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@stibo.com  | 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]