This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Identity Transform and Default Templates, I think...


Schneeman, Brent wrote:
Me again. As I was moving my lessons learned over to the real application, I
noticed that I need a bit more flexibility...

Given this input:

<C3PO>
<SOUL id="anewmachine">The Soul</SOUL>
<BD id="foo">
<HEAD>The Head</HEAD>
<TR>
<RF>The Right Foot</RF>
<RK>The Right Knee</RK>
<HR>The Heart</HR>
<Ext id="extid"><ANewLimb>Some new Limb</ANewLimb></Ext>
<AnotherNewLimb>Another New Limb</AnotherNewLimb>
</TR>
</BD>
</C3PO>

I'd like to have the AnotherNewLimb element copied to the Torso element of
the output document as a sibling of Extension, Chest and RightLeg. But, I'd
like to be able to not be tied to the element name, much like I can rename
SOUL and HEAD and still get the node copied.

If I add
<xsl:apply-templates/>

to the TR template, I wind up applying the RF, RK, HR and Ext templates
twice
If you want to be generic about what's included, you'll
have to be specific about what's to be excluded.

Try
 <xsl:apply-templates select="*[not(self::RF or self::RK or self::HR or self::Ext)]"/>

If this gets too messy, declare the excluded (or included)
elements in another form. One possibility is to declare them
in the stylesheet:
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:data="uri:my.data"
  exclude-result-prefixes="data"/>

 <data:excludes>
   <exclude name="RF"/>
   <exclude name="RK"/>
   <exclude name="HR"/>
   <exclude name="Ext"/>
 </data:excludes>

 <xsl:variable name="excludes"
  select="document('')/xsl:stylesheet/data:excludes"/>

 <xsl:template ....
  ...
   <xsl:apply-templates select=*[not(name()=$excludes/exclude/@name)]"/>

Beware: untested.

J.Pietschmann


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]