xsl-list
[Top] [All Lists]

RE: filter

2002-12-04 11:19:00
Thanks Tom, you always take sth new to me.

Paul

--- TSchutzerWeissmann(_at_)uk(_dot_)imshealth(_dot_)com wrote:
Hi Paul,

and the fact is group element will always apply to

a structure:

/xs:element/xs:complexType/xs:sequence/xs:element
with
the occuring of @maxOccurs attribute 

The "/" at the beginning of that XPath is my typo -
it shouldn't be there
because it's short for the document root. The only
element in the schema
that is a child of / is the top node, xs:schema.

Group on

xs:element[xs:complexType/xs:sequence/xs:element/@maxOccurs].
You
don't need "boolean" - if the expression in the
predicate is the empty
node-set then it's equivalent to false.

The negative version of the filter is


xs:element[not(xs:complexType/xs:sequence/xs:element/@maxOccurs)]

This is the modified version...(untested)


============================================================

<xsl:key name="childGroups"

match="xs:element[xs:complexType/xs:sequence/xs:element/@maxOccurs]"
  use="generate-id(
      

(ancestor::xs:element[xs:complexType/xs:sequence/xs:element/@maxOccurs][1]
      | /)[last())"/>

<!-- the ( xyz | / )[last()] will always give you
xyz if it exists,
otherwise the root node. 
      This is because the root node is the very first
node, so any node
comes later than it 
      and will be last of the pair 

      So we can refer to the top group using this key and
the id of the
root element, instead of
      using a long XPath nightmare
-->

<xsl:key name="byGroup"

match="xs:element[not(xs:complexType/xs:sequence/xs:element/@maxOccurs)]"
  use="generate-id(
      
ancestor-or-self::*/preceding-sibling::xs:element


[xs:complexType/xs:sequence/xs:element/@maxOccurs][1]"/>

<!-- notice that the match is just on xs:element -->

<xsl:template match="/xs:schema/xs:element">
  <xsl:apply-templates
select="key('childGroups',generate-id(/))"
mode="recurse"/>
</xsl:template>

<xsl:template match="xs:element" mode="recurse">
  <!-- for each group -->
    <xsl:variable name="me" select="generate-id()"/>

    Group <xsl:value-of select="@ref"/> Starts     
    
    <xsl:apply-templates
select="key('childGroups',$me)" mode="recurse"/>
   
    Group <xsl:value-of select="@ref"/> Ends.
                                        
    <xsl:for-each select="key('byGroup',$me)">
      <xsl:value-of select="@ref"/> Starts
    </xsl:for-each>
    
    <xsl:for-each select="key('byGroup',$me)">
      <xsl:value-of select="@ref"/> Ends
    </xsl:for-each>

</xsl:template>

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



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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



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