xsl-list
[Top] [All Lists]

Re: [xsl] Help with Transformation

2007-10-29 12:23:23
I must say, your source XML is a little funky. In particular I am
talking about the Address nodes and their corresponding Zip nodes.
Correlating them simply by their order isn't necessarily the best way
to do it, nor (as I recall) will the order *always* be respected,
depending on your processor.

I attempted to come up with a full solution for you. May work in a
rickety manner or not at all. As Ken says, because your problem is so
open-ended a better subject for this thread might be 'Someone do this
for me'. Luckily, I have a soft-spot for people who learn by example.

<xsl:template match="/">
        <ListOfCustomers>
                <xsl:apply-templates select="CustomerSet" />
        </ListOfCustomers>
</xsl:template>
<xsl:template match="CustomerSet">
        <xsl:apply-templates select="AddressSet/Address[1]" />
</xsl:template>
<xsl:template match="Address">
        <MyCustomer>
                <Id><xsl:value-of
select="/Customer/CustomerAccount/ResponseHeader/CorrelationId /></Id>
                <AccoutName><xsl:value-of select="../../CustomerName" 
/></AccountName>
                <BillMonth><xsl:value-of select="../As/Above" /></BillMonth>
                <Product><!-- as above --></Product>
                <Address><xsl:value-of select="Address" /></Address>
                <Zip><xsl:value-of select="../ZipSet/Zip[position() =
current()/position()]" /></Zip>
                <!-- I'm honestly not sure if the above wrangling is legal. -->
        </MyCustomer>
</xsl:template>



On 10/29/07, Avaneesh Ramprasad <avaneesh(_at_)rocketmail(_dot_)com> wrote:

Iam fairly new to xsl and iam stuck, i would greatly appreciate if someone 
could help me out here, below are the input and output xml documents

Input xml
<Customer>
   <CustomerAccount>
      <ResponseHeader>
         <CorrelationId>1234</CorrelationId>
   </ResponseHeader>
      <ResponseStatus>
         <Status>Success</Status>
      </ResponseStatus>
      <CustomerSet>
         <CustomerName>Pizza Hut</CustomerName>
         <Product>Product 1</Product>
         <PurchaseMonth>October 2007</PurchaseMonth>
        <AddressSet>
          <Address>1 main st</Address>
          <Address>2 river st</Address>
          <Address>3rd st</Address>
        </AddressSet>
         <ZipSet>
            <Zip>199360</Zip>
            <Zip>94596</Zip>
            <Zip>07974</Zip>
         </ZipSet>
   </CustomerSet>
      <CustomerSet>
         <CustomerName>Dominos</CustomerName>
         <Product>Product 2</Product>
         <PurchaseMonth>October 2007</PurchaseMonth>
        <AddressSet>
          <Address>21 Elm Road</Address>
          <Address>55 Green St</Address>
         </AddressSet>
         <ZipSet>
            <Zip>2583</Zip>
            <Zip>48818</Zip>
         </ZipSet>
   </CustomerSet>
   </CustomerAccount>
<Customer>

Below should be my output after transformation
<ListOfCustomers>
   <MyCustomer>
      <Id>1234</Id>
      <AccountName>Pizza Hut</AccountName>
      <BillMonth>October 2007</BillMonth>
      <Product>Product 1</Product>
      <Address>1 main st</Address>
      <Zip>199360</Zip>
   </MyCustomer>
   <MyCustomer>
      <Id>1234</Id>
      <AccountName>Pizza Hut</AccountName>
      <BillMonth>October 2007</BillMonth>
      <Product>Product 1</Product>
      <Address>2 river st</Address>
      <Zip>94596</Zip>
   </MyCustomer>
   <MyCustomer>
      <Id>1234</Id>
      <AccountName>Pizza Hut</AccountName>
      <BillMonth>October 2007</BillMonth>
      <Product>Product 1</Product>
      <Address>3rd st</Address>
      <Zip>07974</Zip>
   </MyCustomer>
   <MyCustomer>
      <Id>1234</Id>
      <AccountName>Dominos</AccountName>
      <BillMonth>October 2007</BillMonth>
      <Product>Product 2</Product>
      <Address>21 Elm Road</Address>
      <Zip>2583</Zip>
   </MyCustomer>
   <MyCustomer>
      <Id>1234</Id>
      <AccountName>Dominos</AccountName>
      <BillMonth>October 2007</BillMonth>
      <Product>Product 2</Product>
      <Address>55 Green St</Address>
      <Zip>48818</Zip>
   </MyCustomer>
</ListOfCustomers>

Thank you for all your help in advance.





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>