xsl-list
[Top] [All Lists]

RE: implement attribute inheritance

2004-07-13 08:18:34
Write a modified identity template rule:

<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="ancestor-or-self::*/@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

The copy-of will select the attributes in document order (innermost element
last), and where two attributes with the same name are added to an element,
the last one wins, which is the effect you need.

Michael Kay 

-----Original Message-----
From: Emmanouil Batsis [mailto:Emmanouil(_dot_)Batsis(_at_)eurodyn(_dot_)com] 
Sent: 13 July 2004 16:01
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] implement attribute inheritance

Dear gurus,

I'm trying to write a preprocessor script to transform implicit 
inheritance semantics to actual nodes. The target effect is something 
like namespace scopes but I want to inherit attribute-value pairs 
instead of namespace URIs. Then, I'll be able and edit files 
and assume 
scope based inheritance of attributes for readability and 
other reasons.

For example the following:

<root attr1="attr1">
   <grantparent attr2="attr2">
     <parent attr1="changed-by-parent">
       <child>
         <grandchild attr1="changed-by-grandchild"/>
       </child>
     </parent>
   </grantparent>
</root>

should become

<root attr1="attr1">
   <grantparent attr1="attr1" attr2="attr2">
     <parent attr1="changed-by-parent" attr2="attr2">
       <child attr1="changed-by-parent" attr2="attr2">
         <grandchild attr1="changed-by-grandchild" attr2="attr2"/>
       </child>
     </parent>
   </grantparent>
</root>

This of course is easy to implement for a finite number of attributes 
using parameters and call-template, but how can I do this when 
attributes are not known?

Any XSLT 1.0 pointers welcome. XSLT 2.0 pointers would be 
interesting, 
but I wont be able to use them.

Thanks,

Manos

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>