ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] XPath Question.
by Joerg Heinicke other posts by this author
Dec 21 2001 2:46AM messages near this date
[xsl] XPath Question. | RE: [xsl] How to add a top level element to the result ?
Hello Raj,

I created a mapping.xml with the follwing structure:

<mapping> 
    <map OrderId="1001" mapped="1"/> 
    <map OrderId="1002" mapped="2"/> 
    <map OrderId="1003" mapped="3"/> 
    <map OrderId="1004" mapped="4"/> 
</mapping> 

The I have the followng stylesheet:

<xsl:variable name="mapping" select="document('mapping.xml')/mapping"/> 

<xsl:template match="/Customer"> 
    <xsl:text> OUT</xsl:text>
    <xsl:apply-templates select="Order[OrderId = $mapping/map/@OrderId]"/> 
    <xsl:if test="Order[not(OrderId = $mapping/map/@OrderId)]"> 
        <xsl:text> *99</xsl:text>
    </xsl:if> 
</xsl:template> 

<xsl:template match="Order"> 
    <xsl:text> *</xsl:text>
    <xsl:value-of select="$mapping/map[@OrderId =
current()/OrderId]/@mapped"/> 
</xsl:template> 

The output: OUT*1*2*3*4*99.

Hope this helps,

Joerg

>  Hi All,
>  My XML file is some thing like this
> 
>  <Customer>
>  <Order>
>  <OrderId>1001</OrderId>
>  </Order>
>  <Order>
>  <OrderId>1002/OrderId>
>  </Order>
>  <Order>
>  <OrderId>1003</OrderId>
>  </Order>
>  <Order>
>  <OrderId>1004</OrderId>
>  </Order>
>  <Order>
>  <OrderId>1007</OrderId>
>  </Order>
>  <Order>
>  <OrderId>1009</OrderId>
>  </Order>
>  </Customer>
> 
>  I have to print the output by mapping the codes
>  1001 - 1
>  1002 - 2
>  1003 - 3
>  1004 - 4
>  If any OrderId is not in the above mapping table, I have to print 99.
> 
>  Output will be something like this:
>  OUT*1*2*3*4*99*99
> 
>  My Problem here is if I have more than one OrderId codes that does not
match
>  the mapping table, I have to print only one 99.
> 
>  Can any body help me, on How I can do that.
> 
>  Thanks,
>  Raj..


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
Thread:
Avula, Raj
Joerg Heinicke

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved