← Prev in month ← Prev in thread
Next in thread → Next in month →

Re: output node with subnodes "as-is"

From
<>
To
Date
2004-12-03T13:09:45Z
ID
<>
Thread
Re: output node with subnodes "as-is"
>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
← Prev in month ← Prev in thread
Next in thread → Next in month →