Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2006, 05:04 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help !

Hi,

 I'm a newbee to XSLT. Got stuck in couple of issues. I've this following xml.

<ns0:DataArea>
   <ns1:OriginalApplicationArea type="TEST">
    <ns1:CreationDateTime>2006-05-22T11:40:35.228-07:00</ns1:CreationDateTime>
   </ns1:OriginalApplicationArea>
   <ns0:Promotion>
        <ns0:PromotionHeader type = "GENERAL PROMOTION">
       <ns0:PromotionComponent>
            <ns0:Code>PRODUCT</ns0:Code>
            <ns1:Name xmlns:ns1 = "http://www.openapplications.org/oagis/9">Product</ns1:Name>
       </ns0:PromotionComponent>
       <ns0:PromotionComponent>
        <ns0:Code>SERVICE</ns0:Code>
        <ns1:Name xmlns:ns1 = "http://www.openapplications.org/oagis/9">Service</ns1:Name>
       </ns0:PromotionComponent>
        </ns0:PromotionHeader>
        <ns0:PromotionLine>
       <ns0:PromotionDiscountItem type = "Hardware Part Number">
                <ns0:Discount type = "Distributor Discount">
            <ns1:DiscountPercent xmlns:ns1 = "http://www.openapplications.org/oagis/9">57.5</ns1:DiscountPercent>
        </ns0:Discount>
           </ns0:PromotionLine>
        <ns0:Promotion>
</ns0:DataArea>


Here's the XSL I'm using.

<xsl:template match="/">
<body><html>
<table border="0" cellspacing="1" cellpadding="4">
<xsl:for-each select="ns0:DataArea/ns0:Promotion">
     <tr bgcolor="#FFFFFF">
     <td class="tablecontent" align="center">
         <xsl:value-of select="@type"/> --> Here I want to publish the value of type in ns0:PromotionHeader attribute
     </td>
     <xsl:for-each select="ns0:DataArea/ns0:Promotion/ns0:PromotionComponent">
         <td class="tablecontent" align="center">
             <xsl:value-of select="ns0:PromotionComponent/ns1:Name"/>
         </td>
     </xsl:for-each>
     </tr>
</xsl:for-each>
</table>
</body></html>
</xsl:template>

First issue, I'm trying to publish the value of select attribute for ns0:PromotionHeader element, but its coming as blank.Since there are Type attribute present for ns0:PromotionDiscountItem and ns1:OriginalApplicationArea, how will I distinguish from them.

Second issue,for the second for loop, I've to put the values of ns0:PromotionComponent/ns1:Name in a comma seperated string in a single column. For eg. PRODUCT,SERVICE . How can I do that ?

Any pointers on this will be highly appreciated.

Thanks

 
Old June 9th, 2006, 05:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When Promotion is the context node, you can get the type attribute of PromotionHeader as select="ns0:PromotionHeader/@type".

Your inner for each should be

<xsl:for-each select="ns0:PromotionComponent">

because it's selecting relative to the Promotion element.

Read up about the context node and the effect of various constructs on the context. To write path expressions, you always need to know what the context node is at any point.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 10th, 2006, 08:04 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help, I figured out how to build the comma seperated string










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.