[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XSL Trnasfromation - Is it possible to do a bottom up transformation?


Subject: Re: [xsl] XSL Trnasfromation - Is it possible to do a bottom up transformation?
From: "Raghu Narayan Koratagere" <raghu.k.n@xxxxxxxxx>
Date: Mon, 19 Nov 2007 16:01:31 +0530

Micheal,

To clarify, here are the source and example of transformed xmls:

Source Tree:
=========
<orderline>
      <linenum>1</linenum>
      <productName>Computer</productName>
      <netPrice>100</netPrice>
      <itemTypeCode>3</itemTypeCode>
      <quantity>1</quantity>
      <orderline>
          <linenum>1.1</linenum>
          <productName>CPU</productName>
          <netPrice>100</netPrice>
          <itemTypeCode>3</itemTypeCode>
          <quantity>2</quantity>
          <orderline>
              <linenum>1.1.1</linenum>
              <productName>Mother Board</productName>
              <netPrice>100</netPrice>
              <itemTypeCode>2</itemTypeCode>
              <quantity>2</quantity>
          </orderline>
          <orderline>
              <linenum>1.1.2</linenum>
              <productName>Processor</productName>
              <netPrice>200</netPrice>
              <itemTypeCode>2</itemTypeCode>
              <quantity>2</quantity>
          </orderline>
    </orderline>
    <orderline>
        <linenum>2</linenum>
        <productName>Table</productName>
        <netPrice>100</netPrice>
        <itemTypeCode>2</itemTypeCode>
        <quantity>1</quantity>
    </orderline>
    <orderline>
        <linenum>3</linenum>
        <productName>UPS</productName>
        <netPrice>100</netPrice>
        <itemTypeCode>1</itemTypeCode>
        <quantity>1</quantity>
    </orderline>
</orderline>


Transformed Tree:
=============
<orderline>
      <linenum>1</linenum>
      <productName>Computer</productName>
      <netPrice>100</netPrice>
      <itemTypeCode>3</itemTypeCode>
      <unitPrice>350</unitPrice> <!-- 150+100+100=350 -->
      <quantity>1</quantity>
      <orderline>
          <linenum>1.1</linenum>
          <productName>CPU</productName>
          <netPrice>100</netPrice>
          <itemTypeCode>3</itemTypeCode>
          <unitPrice>150</unitPrice> <!-- 50+100=150 -->
          <quantity>2</quantity>
          <orderline>
              <linenum>1.1.1</linenum>
              <productName>Mother Board</productName>
              <netPrice>100</netPrice>
              <itemTypeCode>2</itemTypeCode>
              <unitPrice>50</unitPrice> <!-- 100/2=50 -->
              <quantity>2</quantity>
          </orderline>
          <orderline>
              <linenum>1.1.2</linenum>
              <productName>Processor</productName>
              <netPrice>200</netPrice>
              <itemTypeCode>2</itemTypeCode>
              <unitPrice>100</unitPrice> <!-- 200/2=100 -->
              <quantity>2</quantity>
          </orderline>
    </orderline>
    <orderline>
        <linenum>2</linenum>
        <productName>Table</productName>
        <netPrice>100</netPrice>
        <itemTypeCode>2</itemTypeCode>
        <unitPrice>100</unitPrice> <!-- 100/1=100 -->
        <quantity>1</quantity>
    </orderline>
    <orderline>
        <linenum>3</linenum>
        <productName>UPS</productName>
        <netPrice>100</netPrice>
        <itemTypeCode>1</itemTypeCode>
        <unitPrice>100</unitPrice> <!-- 100/1=100 -->
        <quantity>1</quantity>
    </orderline>
</orderline>


Issue:
====
When the template matches line with LineNumber 1, the UnitPrice for
LineNumber 1.1, 2, 3 are not yet know. So what values will the
function take to calculate?

I have not tried using the below rule, will try :
<xsl:template match="unitPrice[../itemTypeCode = '3']">
   <xsl:copy><xsl:value-of select="sum(../unitPrice[1] div
../quantity[1])" /></xsl:copy>
</xsl:template>

Thanks,
Raghu


On 11/19/07, Michael Kay <mike@xxxxxxxxxxxx> wrote:
>
> > The problem is here you are transforming top down.
>
> I don't understand your fixation with these terms bottom-up and top-down.
> Think functionally: x is a function of y. And it really doesn't matter
> whether a transformation is top-down, bottom-up, outside-in, or inside-out,
> so long as it produces the right answer.
>
> If Abel's solution produces the wrong answer then you need to explain the
> requirement more clearly. Sample input and output is often useful if it's
> difficult to explain it in clear English.
>
> Michael Kay
> http://www.saxonica.com/


Current Thread