OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: output node with subnodes "as-is"

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Re: output node with subnodes "as-is"
  • From: richard@inf.ed.ac.uk (Richard Tobin)
  • Date: Fri, 3 Dec 2004 13:09:45 +0000 (GMT)
  • Cc:
  • In-reply-to: <yg48y8f1xz7.fsf@penguin.nag.co.uk>
  • Organization: HCRC, University of Edinburgh
  • References: <17ee29ab.0412030020.34bb97be@posting.google.com>

>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




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS