Re: [xsl] create escaped(?) html of some nodes

Subject: Re: [xsl] create escaped(?) html of some nodes
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Tue, 10 Oct 2006 10:29:13 +0200 (CEST)
Jan Limpens wrote:


> but I have no Idea how I can transform using

> 	<xsl:template match="entry:Image">
> 		<p class="ImageParagraph">
> 			<img src="{$application-path}{@href}" alt="{entry:Title}" />
> 			<br />
> 			<xsl:value-of select="entry:Description" />
> 		</p>
> 	</xsl:template>

> and escape the html (make the brackets become %lt;) as well.

  You have two main options: 1/ create the nodes for resulting HTML,
then serialize them, or 2/ create directly text nodes.  1/ will looks
to something like this:

    <xsl:template match="entry:Image">
      <xsl:text>  &_lt;p class="ImageParagraph"&_gt;</xsl:text>
        <xsl:text>    &_lt;img src="</xsl:text>
        <xsl:value-of select="$application-path"/>
        <xsl:value-of select="@href"/>
        <xsl:text>" alt="</xsl:text>
        <xsl:value-of select="entry:Title"/>
        <xsl:text>    &_lt;br/&_gt;</xsl:text>
        <xsl:value-of select="entry:Description"/>
      <xsl:text>  &_lt;/p&_gt;</xsl:text>

  For 2/, you have to use you prefered xx:node-set() extension or XSLT
2.0.  You then create the template rules that make the escaping, in a
particular mode:

    <xsl:template match="*" mode="serialize">
      <xsl:value-of select="name()"/>
      <xsl:apply-templates select="@*" mode="serialize"/>
      <xsl:apply-templates select="node()" mode="serialize"/>
      <xsl:value-of select="name()"/>

  Or you can use your favorite serialize extension or module.




Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions ! 
Demandez ` ceux qui savent sur Yahoo! Questions/Riponses

Current Thread