xsl-list
[Top] [All Lists]

Re: [xsl] alternative to repeatedly walking the ancestor axis in 1.0

2008-08-01 12:10:28
which leaves walking the ancestor axis most of the time

Keys are for this:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kRtlMode" match="*[ancestor-or-self::*[(_at_)dir='rtl']]"
 use="generate-id()"/>

 <xsl:template match="node()|@*" name="identity">
   <xsl:copy>
     <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="*[key('kRtlMode',generate-id())]">
   <xsl:copy>
     <xsl:attribute name="rtlDetected">true</xsl:attribute>
     <xsl:apply-templates select="node()|@*" />
   </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

Applied upon this xml document:

<foo>
        <bar dir="rtl">
                <baz>...</baz>
        </bar>
</foo>

Produces the wanted result:

<foo>
   <bar rtlDetected="true" dir="rtl">
      <baz rtlDetected="true">...</baz>
   </bar>
</foo>


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play





On 8/1/08, Andrew Welch <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> wrote:
I wonder if there are any cunning solutions to this problem:

- An attribute which indicates right-to-left text can occur on any
element in the input
- All elements in the output beneath that element should then have a
certain style

For example:

<foo>
 <bar dir="rtl">
   <baz>...

The output for both bar and baz should contain the style.

Using 2.0 I guess the solution would be tunnelled paramters, but in
1.0 you'd have to manually pass the parameters - which isn't
practical...  which leaves walking the ancestor axis most of the time
checking for the dir attribute.

Are there any other ways?   Or is walking the ancestor axis no big
deal, especially when the input tree is likely to be a DOM?


--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>