File: bug-90.xsl

package info (click to toggle)
libxslt 1.1.43-0.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,188 kB
  • sloc: xml: 66,120; ansic: 36,035; sh: 4,582; python: 3,206; makefile: 1,378; javascript: 470; perl: 34
file content (35 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?xml version="1.0"?>
<!-- 
============================================================
This is a stylesheet that will create, for each input <fruit> element,
two output elements - <new-fruit1> and <new-fruit2> , each of
which should wrap the content of the the input fruit/site element
in a CDATA block.
<new-fruit1> does this 'properly' via  cdata-section-elements
<new-fruit2> does it with a workaround named template 'wrap-cdata'
============================================================
 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" cdata-section-elements="new-fruit1" indent="yes"/>
  <xsl:template match="fruit-sites/fruit">
    <new-fruit1 type="{@type}">
      The site is at
      <xsl:value-of select="./site"/>
    </new-fruit1>
    <new-fruit2 type="{@type}">
      <xsl:call-template name="wrap-cdata">
        <xsl:with-param name="content">
	  The site is at <xsl:value-of select="./site"/>
        </xsl:with-param>
      </xsl:call-template>
    </new-fruit2>
  </xsl:template>

  <!-- Wrap $content in a CDATA block  -->
  <xsl:template name="wrap-cdata">
    <xsl:param name="content"/>
    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text> <!--
    --><xsl:value-of disable-output-escaping="yes" select="$content"/> <!-- 
    --><xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  </xsl:template>
</xsl:stylesheet>