[Home] [By Thread] [By Date] [Recent Entries]

  • To: xml-dev@l...
  • Subject: Re: output node with subnodes "as-is"
  • From: richard@i... (Richard Tobin)
  • Date: Fri, 3 Dec 2004 13:09:45 +0000 (GMT)
  • Cc:
  • In-reply-to: <yg48y8f1xz7.fsf@p...>
  • Organization: HCRC, University of Edinburgh
  • References: <17ee29ab.0412030020.34bb97be@p...>

>A more usual case is where you want templates
>that do an identity transform but then have higher priority templates
>for certain special attributes that do something other than copy.

I wish XSLT had provided the identity transform as the default
template instead of the markup-stripping ones.

We find this case so common that I have recently written a program
that takes a single template on the command line and inserts it
into a stylesheet with a low-priority identity template:

  lxreplace -q match-expr -t template-body

To make it even simpler for the simple cases, the stylesheet defines
some entities:

 <!ENTITY this
          "<xsl:copy><xsl:apply-templates select='@*|node()'/></xsl:copy>">
 <!ENTITY attrs "<xsl:apply-templates select='@*'/>">
 <!ENTITY children "<xsl:apply-templates select='node()'/>">
 <!ENTITY text "<xsl:value-of select='.'/>">

Simple examples are wrapping elements:

  lxreplace -q 'foo[@bar="unknown"]' -t '<bogus>&this;</bogus>'

renaming elements:

  lxreplace -q 'foo' -t '<bar>&attrs;&children;</bar>'

and moving the text content of an element into an attribute:

  lxreplace -q 'foo' -t '<foo value="{.}"/>'

-- Richard

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member