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

Re: [xsl] XPath Question.


Subject: Re: [xsl] XPath Question.
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Sat, 22 Dec 2001 03:38:16 +0100

Yes, this is one method for getting your 99 only once, but it isn't very
generic. Because of this I created a second file. There you can add other
IDs or change the mappings. But if you don't want ;-)

But your 99 you can have easier:

<xsl:for-each select="/Customer/Order[not(contains(' 1001 1002 1003 1004 ',
OrderId))][1]">
    <xsl:text>*99</xsl:text>
</xsl:for-each>

This means: for every order test, whether the OrderId is in the list. Then
take the first one and only the first one of them all, whose OrderId isn't
in the list. So it's only one iteration and one '*99'. Nothing with a
temp-variable or call-template.

Regards,

Joerg

> I got it. It is something like
>
> <xsl:variable name="temp">
> <xsl:call-templates name="print_order" />
> </xsl:variable>
>
> <xsl:if test="contains(temp, '99')>
> <xsl:text>*99</xsl:text>
> </xsl:if>
>
> <xsl:template name="print_order">
> <xsl:for-each "/Customer/Order">
> <xsl:choose>
> <xsl:when test="OrderId=1001">
> </xsl:when>
> <xsl:when test="OrderId=1002">
> </xsl:when>
> <xsl:when test="OrderId=1003">
> </xsl:when>
> <xsl:when test="OrderId=1004">
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>*99</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:for-each>
> </xsl:template>
>
> -- Do you guys think of any easier way of doing this.
>
>
> --Thanks
> Raj..
>
> > > 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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread