Re: [xsl] total newbie

Subject: Re: [xsl] total newbie
From: Bill Smith <bfaith1us@xxxxxxxxx>
Date: Fri, 12 Jun 2009 06:22:23 -0700 (PDT)
Excellent!  Thanks!  I was trying to shorten it up a bit since it seemed like
my post was getting really long.  I guess I know less than I thought I did. 
Thanks again.



----- Original Message ----
From: Sam Byland
<shbyland@xxxxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Thursday,
June 11, 2009 2:12:23 PM
Subject: Re: [xsl] total newbie

Bill,

It will make
it easier on us if your sample XML is well formed, and contains the content
that results in your sample output.  The XML you provided isn't well formed,
and doesn't contain the text values you are showing in your sample output.
Guessing as to what was in your sample input XML that results in your output,
I am thinking you had something like this:

<EntireOrder>
  <PO>
   
<POHeader>
        <SomeHeaderInfo1>Steve</SomeHeaderInfo1>
       
<SomeHeaderInfo2>555-5555</SomeHeaderInfo2>
    </POHeader>
    <POLine>
     
  <SomeOtherLineInfo>100</SomeOtherLineInfo>
       
<SomeLineInfo2>Tags</SomeLineInfo2>
        <SomeLineInfo3>10</SomeLineInfo3>
        <SomeLineInfo4>1000</SomeLineInfo4>
        <ShipTo>
         
<ShipInfo1>Walmart</ShipInfo1>
        </ShipTo>
    </POLine>
    <POLine>
 
      <SomeOtherLineInfo>100</SomeOtherLineInfo>
       
<SomeLineInfo2>Tags</SomeLineInfo2>
        <SomeLineInfo3>10</SomeLineInfo3>
        <SomeLineInfo4>1000</SomeLineInfo4>
        <ShipTo>
         
<ShipInfo1>Walmart</ShipInfo1>
        </ShipTo>
    </POLine>
  </PO>
</EntireOrder>

However, I would then expect you to have "Walmart" appearing
twice in your output, and in your post it appears only once....

That aside,
this might do what you're looking for:

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

  <xsl:output method="xml"
indent="yes"/>

  <xsl:template match="/">

    <Orders>

       
<xsl:for-each select="EntireOrder/PO/POLine">
          <Order>
             
<ShipToCustomer>
                <xsl:apply-templates
select="ShipTo/ShipInfo1"/>
              </ShipToCustomer>
             
<Description>
                <xsl:apply-templates select="SomeLineInfo2"/>
 
            </Description>
              <Quantity>
               
<xsl:apply-templates select="SomeOtherLineInfo"/>
              </Quantity>
 
            <Buyer>
                <xsl:apply-templates
select="../POHeader/SomeHeaderInfo1"/>
              </Buyer>
             
<Phone>
                <xsl:apply-templates
select="../POHeader/SomeHeaderInfo2"/>
              </Phone>
             
<UnitPrice>
                <xsl:apply-templates select="SomeLineInfo3"/>
   
          </UnitPrice>
              <Total>
               
<xsl:apply-templates select="SomeLineInfo4"/>
              </Total>
         
</Order>
        </xsl:for-each>

    </Orders>

  </xsl:template>
</xsl:stylesheet>

The above stylesheet applied to the corrected XML I pasted
above yields:

<Orders>
  <Order>
    <ShipToCustomer>Walmart</ShipToCustomer>
    <Description>Tags</Description>
    <Quantity>100</Quantity>
   
<Buyer>Steve</Buyer>
    <Phone>555-5555</Phone>
    <UnitPrice>10</UnitPrice>
    <Total>1000</Total>
  </Order>
  <Order>
   
<ShipToCustomer>Walmart</ShipToCustomer>
    <Description>Tags</Description>
 
  <Quantity>100</Quantity>
    <Buyer>Steve</Buyer>
   
<Phone>555-5555</Phone>
    <UnitPrice>10</UnitPrice>
    <Total>1000</Total>
  </Order>
</Orders>

Hope that helps,

...sam

Current Thread