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

RE: favor certain elements

Subject: RE: favor certain elements
From: Emmanuel Bégué <eb@xxxxxxxxxx>
Date: Tue, 20 Oct 2009 06:57:11 +0200
RE:  favor certain elements
Hello,

Have you tried grouping? Using this template:

<xsl:template match="/root">
  <root>
    <elementx>
      <xsl:for-each-group select="*/*" group-by="local-name()">
        <xsl:choose>
          <xsl:when test="local-name()='a'">
            <xsl:copy-of select="current-group()[1]"/>
            </xsl:when>
          <xsl:when test="local-name()='b'">
            <xsl:copy-of select="current-group()[last()]"/>
            </xsl:when>
          <xsl:otherwise>
            <!-- some default rule should go here -->
            <xsl:copy-of select="current-group()[1]"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each-group>
      </elementx>
    </root>
  </xsl:template>

this source:

<root>
   <element1>
       <a>first a (from 1)</a>
       <b>first b (from 1)</b>
   </element1>
   <element2>
       <a>second a (from 2)</a>
       <b>second b (from 2)</b>
       <c>first c (from 2)</c>
   </element2>
   <element3>
       <a>third a (from 3)</a>
       <b>third b (from 3)</b>
       <c>second c (from 3)</c>
   </element3>
</root>

gives this result:

<root>
   <elementx>
      <a>first a (from 1)</a>
      <b>third b (from 3)</b>
      <c>first c (from 2)</c>
   </elementx>
</root>

Regards,
EB


> -----Original Message-----
> From: Szabo, Patrick (LNG-VIE) [mailto:patrick.szabo@xxxxxxxxxxxxx]
> Sent: Monday, October 19, 2009 4:08 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  favor certain elements
>
>
> Hi,
>
> Im using Saxon 9, and XSLT 2.0.
>
> Source:
>
> <root>
>     <element1>
>         <a>...</a>
>         <b>...</b>
>     </element1>
>     <element2>
>         <a>...</a>
>         <b>...</b>
>         <c>...</c>
>     </element2>
> </root>
>
> desired output:
>
> <root>
>     <elementx>
>         <a>...</a>
>         <b>...</b>
>         <c>...</c>
>     </elementx>
> </root>
>
> What i want do do is to apply templates to the elements a, b, c.
> The problem is that there is an element a in element1 and another
> in element2. (same thing with element b)
> Is there a way to favor certain elements ?!
> If there is an element a in element1 and element2 i want to use
> the a from element2 - if there isnt i want to use the a from element1.
> I want to to the same thing with b but contrariwisely.
>
> What i want is something like.
>
> <xsl:apply-templates select="//a" fav="parent::element2"/>
>
> I hope i explained the question sufficiently !
>
> regards
>
>
> Patrick Szabo
>  XSLT-Entwickler
>
> Tel.: +43 (1) 534 52 - 1573
> Fax: +43 (1) 534 52 - 146
>
> Patrick.Szabo@xxxxxxxxxxxxx
>
> LexisNexis Verlag ARD Orac GmbH & Co KG
> Marxergasse 25, 1030 Wien
> FN 8333f, Handelsgericht Wien
> http://www.lexisnexis.at/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.