[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Matching a recursive local element structure

Subject: Re: Matching a recursive local element structure
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Fri, 4 Feb 2011 19:41:27 -0500
Re:  Matching a recursive local element structure
Hi David! I think you're asking "how do I match C when its closest
ancester B is closer than its closest ancester A", right?

In which case, perhaps something like

  <xsl:template match="C">
      <xsl:when test="generate-id( (ancestor::A|ancestor::B)[1] ) =
generate-id( ancestor::A[1] )">
        <!-- do A//C stuff -->
      <xsl:when test="generate-id( (ancestor::A|ancestor::B)[1] ) =
generate-id( ancestor::B[1] )">
        <!-- do B//C stuff -->
        <xsl:message>Well I'll be -- it appears I have neither an A nor B

would do the trick? (Untested.)

Of course this template catches each C in /A/B/C/A/B/C/A/B/C, and
processes them all on the B branch. Did you only want the leaf C?

> Suppose I have a schema which describes a recursive structure as local
> elements.
> Example (pseudo DTD, and pseudo xml I can provide more formal defs if
> )
> Element section  (text)*
> Element text ( list | para | bold | #PCDATA )*
> Element list ( item*)
> Element item ( text | subheading ) *
> Element subheading (text)*
> So for example doc may look like
> <section>
>   <text>Text
>        <list>
>                        <item><para>Item Text</para></item>
>                        <item><para>Item Text2</para></item>
>                        <item><para>Item Text</para>
>        <list><item><para>More text> </item></list></para></item>
>                 </list>
>    </text>
> </section>
> The key point is that the schema is recursive, so an xpath (or xslt match)
> might be
>                 section/text
>                 section/text/list/item/para
> section/text/list/item/list/item/list/item/list/item/list/item . Can get
> really long here !!!!
> Now suppose I want to avoid an infinite number of XSLT match strings but I
> want to match say list/item but ONLY within section/text
> (presume there may be a different list/item locally defined within say
> subheader)
> Suggestions on to a good way to do that ?
> <template match=section/text//list/item > 
> But this might match
>                 section/text/subheading/list/item
> or
>                 section/text/list/item/subheading/list/item
> which I dont want.
> I only want to match the list/item which is a local element definition
> below section  (recursively),.
> so the match should select
>                 section/text/list/item/list/item/list/item
> but not
>                 section/text/list/item/subheading/list/item
> ( which I would say match with
>                 subheading/list/item
>                 subheading/list/item/list/item
> )
> Is there an obvious way to do this ?
> Its entirely possible that Im asking an impossible question (that is the
> schemas may simply not allow this restriction in the first place),
> But Im trying to solve a general problem so asking a general question.
> This is based on generating match strings from XSD element declarations so
> its really a XSD question as well 
> Maybe its impossible to describe a schema such that a descendant
> is distinguishable if its under section or subheading ?
> Thanks for any suggestion !

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.