[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: filter
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|