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

Ordering XML with conditions than generate new associ

Subject: Ordering XML with conditions than generate new associations.
From: "Gabriel Osorio" <gosorio@xxxxxxxxxxx>
Date: Fri, 23 Sep 2005 14:27:25 -0400
substring salary 1 2
Hi All, 

(I hope that you could forget and excuse my incorrect use of the language.)

 

This is a summarized example of my actual task. 

Ibm requesting help to the listbs members because I canbt find a correct solution.

 

--------------------------------------------------

My XSL is:

--------------------------------------------------

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

<xsl:key name="order1" match="grade" use="((substring(var/pay,1,1))='') or ((substring(var/pay,1,1))='C')" />

<xsl:key name="order2" match="grade" use="concat(((substring(var/pay,1,1))='') or ((substring(var/pay,1,1))='C'),course[1]/teacher)" />

 

<xsl:template match='root'>

 

  <table>

  <!--Expecial logic for C pay nodes.-->

    <xsl:for-each select="grade[count(. | key('order1', 'true')[1]) = 1]">

      <xsl:if test="generate-id()=generate-id(key('order1', 'true'))">

      <tr><td><div><xsl:attribute name="id">credit_offer</xsl:attribute><table>

      <tr><td>Credit Offer</td></tr>

      <xsl:for-each select="key('order1', 'true')">

            <xsl:sort select="var/price" order="ascending" data-type="number"/>

                  <xsl:call-template name="course"/>

        </xsl:for-each>

      </table></div></td></tr>

        </xsl:if>

    </xsl:for-each>

    

  <!--Logic to group nodes with standar pays-->

    <xsl:for-each select="grade[count(. | key('order2', concat('false',course[1]/teacher))[1]) = 1]">

    <xsl:if test="generate-id()=generate-id(key('order2', concat('false',course[1]/teacher)))">

      <tr><td><div><xsl:attribute name="id"><xsl:value-of select="course[1]/teacher"/></xsl:attribute><table>

      <tr><td>Teacher's Leader: <xsl:value-of select="course[1]/teacher"/></td></tr>

      <xsl:for-each select="key('order2', concat('false',course[1]/teacher))">

        <xsl:sort select="var/price" order="ascending" data-type="number"/>

                  <xsl:call-template name="course"/>

        </xsl:for-each>

        </table></div></td></tr>

      </xsl:if>

    </xsl:for-each>

    

  </table>

  

</xsl:template>

 

<!--The rest.-->

<xsl:template name="course"> 

  <tr>

    <td><xsl:value-of select="position()"/>.</td>

    <td>Price: <xsl:value-of select="var/price"/>.</td>

    <td><xsl:apply-templates select='course'/></td>

  </tr>

</xsl:template>

 

<xsl:template match="course">

    <br/>teacher: <xsl:value-of select="teacher"/>&#xa0;&#xa0;

    class: <xsl:value-of select="class"/>&#xa0;&#xa0;

    shift: <xsl:value-of select="shift"/>&#xa0;&#xa0;

    Pay: <xsl:value-of select="../var/pay"/>

</xsl:template>

 

</xsl:stylesheet>

 

--------------------------------------------------

The XML is:

--------------------------------------------------

<?xml version="1.0" ?>

<?xml-stylesheet href="AO_Test_Min.xsl" type="text/xsl"?>

<root>

      <grade>

            <course>

                  <class>1</class>

                  <shift>0</shift>

                  <teacher>Z</teacher>

            </course>

            <course>

                  <class>2</class>

                  <shift></shift>

                  <teacher>na</teacher>

            </course>

            <var>

              <pay></pay>

              <price>200</price>

            </var>

      </grade>

      <grade>

            <course>

                  <class>1</class>

                  <shift>1</shift>

                  <teacher>X</teacher>

            </course>

            <course>

                  <class>2</class>

                  <shift></shift>

                  <teacher>X</teacher>

            </course>

            <var>

              <pay>All</pay>

              <price>170</price>

            </var>

      </grade>

      <grade>

            <course>

                  <class>1</class>

                  <shift>1</shift>

                  <teacher>Y</teacher>

            </course>

            <course>

                  <class>2</class>

                  <shift></shift>

                  <teacher>Y</teacher>

            </course>

            <var>

              <pay>Basic</pay>

              <price>150</price>

            </var>

      </grade>

      <grade>

            <course>

                  <class>1</class>

                  <shift>0</shift>

                  <teacher>X</teacher>

            </course>

            <course>

                  <class>2</class>

                  <shift></shift>

                  <teacher>X</teacher>

            </course>

            <var>

              <pay>Credit</pay>

              <price>100</price>

            </var>

      </grade>

      <grade>

            <course>

                  <class>1</class>

                  <shift>1</shift>

                  <teacher>Z</teacher>

            </course>

            <course>

                  <class>2</class>

                  <shift></shift>

                  <teacher>Z</teacher>

            </course>

            <var>

              <pay>All</pay>

              <price>100</price>

            </var>

      </grade>

      <grade>

            <course>

                  <class>1</class>

                  <shift>1</shift>

                  <teacher>X</teacher>

            </course>

            <course>

                  <class>2</class>

                  <shift></shift>

                  <teacher>na</teacher>

            </course>

            <var>

              <pay>All</pay>

              <price>70</price>

            </var>

      </grade>

</root>

--------------------------------------------------

I wish this output:

--------------------------------------------------

Teacher's Leader: X 

1. Price: 70. 

teacher: X    class: 1   shift: 1   Pay: All

teacher: na   class: 2   shift:     Pay: All 

2. Price: 170. 

teacher: X    class: 1   shift: 1   Pay: All

teacher: X    class: 2   shift:     Pay: All 

 

Teacher's Leader: Z 

1. Price: 100. 

teacher: Z    class: 1   shift: 1   Pay: All

teacher: Z    class: 2   shift:     Pay: All 

 

Credit Offer 

1. Price: 100. 

teacher: X    class: 1   shift: 0   Pay: Credit

teacher: X    class: 2   shift:     Pay: Credit 

2. Price: 200. 

teacher: Z    class: 1   shift: 0   Pay: 

teacher: na   class: 2   shift:     Pay:  

 

Teacher's Leader: Y 

1. Price: 150. 

teacher: Y    class: 1   shift: 1   Pay: Basic

teacher: Y    class: 2   shift:     Pay: Basic

 

--------------------------------------------------

But I have this output:

--------------------------------------------------

Credit Offer 

1. Price: 100. 

teacher: X    class: 1   shift: 0   Pay: Credit

teacher: X    class: 2   shift:     Pay: Credit 

2. Price: 200. 

teacher: Z    class: 1   shift: 0   Pay: 

teacher: na   class: 2   shift:     Pay:  

 

Teacher's Leader: X 

1. Price: 70. 

teacher: X    class: 1   shift: 1   Pay: All

teacher: na   class: 2   shift:     Pay: All 

2. Price: 170. 

teacher: X    class: 1   shift: 1   Pay: All

teacher: X    class: 2   shift:     Pay: All 

 

Teacher's Leader: Y 

1. Price: 150. 

teacher: Y    class: 1   shift: 1   Pay: Basic

teacher: Y    class: 2   shift:     Pay: Basic

 

Teacher's Leader: Z 

1. Price: 100. 

teacher: Z    class: 1   shift: 1   Pay: All

teacher: Z    class: 2   shift:     Pay: All 

 

--------------------------------------------------

 

My problem lies on canbt establish a new group over node bcourse[1]/teacherb.

 

The Objectives are:

This is languagebs teacher board offer. I need sort teacherbs offers by price. And sort teachers from cheapest to most expensive. 

With this rule: bIf the course can pay with credit card or is not informed, itbs a promotion.b 

The promotions are a new group. And carry out the teacherbs rules.

Other additional complication: courses have two or more teachers. And the sorted group uses the first teacherbs name.

 

Thanks for your help, in advance.

 

Gabriel

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.