xslt - It is possible to set a priority on a "group-starting-with"-clause? -


this example of input file.

<root>     <!-- [...] -->     <bbb>foo 1</bbb>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <bbb>foo 2</bbb>     <ccc>foo 2.1</ccc>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <bbb>foo 3</bbb>     <ccc>foo 3.1</ccc>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <ccc>foo 4</ccc>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa>     <aaa>xxxxxxxx</aaa> </root> 

i want group nodes bbb , ccc elements. possible there bbb or ccc in input-xml.

there following conditions:

  • condition a: group "bbb" or "ccc" element
  • condition b: if "ccc" following "bbb" take them together

this outpout-xml want have:

 <root>         <group>             <header>foo 1</header>                 <groupcontent>                     <aaa>xxxxxxxx</aaa>                     <aaa>xxxxxxxx</aaa>                     <aaa>xxxxxxxx</aaa>                 </groupcontent>         </group>         <group>             <header>foo 2</header>             <subheader>foo 2.1</subheader>             <groupcontent>                 <aaa>xxxxxxxx</aaa>                 <aaa>xxxxxxxx</aaa>                 <aaa>xxxxxxxx</aaa>             </groupcontent>         </group>         <group>             <header>foo 3</header>             <subheader>foo 3.1</subheader>             <groupcontent>                 <aaa>xxxxxxxx</aaa>                 <aaa>xxxxxxxx</aaa>                 <aaa>xxxxxxxx</aaa>             </groupcontent>         </group>         <group>             <subheader>foo 4</subheader>             <groupcontent>                 <aaa>xxxxxxxx</aaa>                 <aaa>xxxxxxxx</aaa>                 <aaa>xxxxxxxx</aaa>             </groupcontent>         </group>     </root> 

currently have following xsl. problem generates foreach "foo" "group"-element.

<xsl:stylesheet>       <xsl:output method="xml" encoding="utf-8" indent="yes"/>      <xsl:template match="/">     <output>             <xsl:for-each-group select="root/*" group-starting-with="bbb|ccc">                 <group>                         <xsl:apply-templates select="current-group()[self::bbb or self::ccc]"></xsl:apply-templates>                         <groupcontent>                             <xsl:apply-templates select="current-group()[not(self::bbb) , not (self::ccc)]"></xsl:apply-templates>                         </groupcontent>                 </group>             </xsl:for-each-group>         </output>     </xsl:template>      <xsl:template match="bbb">         <header><xsl:value-of select="."></xsl:value-of></header>     </xsl:template>      <xsl:template match="ccc">         <subheader><xsl:value-of select="."></xsl:value-of></subheader>     </xsl:template>      <xsl:template match="aaa">         <p><xsl:value-of select="."></xsl:value-of></p>     </xsl:template>  </xsl:stylesheet> 

how can add condition b xsl. possible solve 1 foreach-group? can add condition b "group-starting-with" , give higher priority condition a? have read can give patterns priority...

thx in advance cpt.oneeye

preserving stylesheet style, stylesheet:

<xsl:stylesheet version="2.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output omit-xml-declaration="yes" indent="yes"/>   <xsl:template match="/">  <output>   <xsl:for-each-group select="root/*" group-starting-with=     "bbb|ccc[preceding-sibling::*[1][not(self::bbb)]]">     <group>       <xsl:apply-templates select=         "current-group()[self::bbb or self::ccc]"/>       <groupcontent>         <xsl:apply-templates select=           "current-group()[not(self::bbb) , not (self::ccc)]"/>       </groupcontent>     </group>   </xsl:for-each-group>  </output> </xsl:template> <xsl:template match="bbb">  <header>   <xsl:value-of select="."/>  </header> </xsl:template> <xsl:template match="ccc">  <subheader>   <xsl:value-of select="."/>  </subheader> </xsl:template> <xsl:template match="aaa">  <p>   <xsl:value-of select="."/>  </p> </xsl:template> 

output:

<output>     <group>         <header>foo 1</header>         <groupcontent>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>         </groupcontent>     </group>     <group>         <header>foo 2</header>         <subheader>foo 2.1</subheader>         <groupcontent>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>         </groupcontent>     </group>     <group>         <header>foo 3</header>         <subheader>foo 3.1</subheader>         <groupcontent>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>         </groupcontent>     </group>     <group>         <subheader>foo 4</subheader>         <groupcontent>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>             <p>xxxxxxxx</p>         </groupcontent>     </group> </output> 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -