Help on xsl choose

Get new comments by email
You can cancel email alerts at anytime.
Comments (3)

Priya9 in Auckland, New Zealand

63 months ago

Hi there

I am having a problem using xsl choose statement. I have the code as follows.

<!--<xsl:value-of select="New_Product" />-->
<xsl:choose>
<xsl:when test=".[New_Product=1]">
New
</xsl:when>
<xsl:otherwise>
Old
</xsl:otherwise>
</xsl:choose>

The XSL doesn't seem to parse when I include the xsl choose statement. If I exclude that I get all the results.

What I need to achieve is to highlight the new products whose value I am getting from the database. When I just use the <xsl:value-of select="New_Product" /> I get the value as 1 or 0.

Can anyone help me identify what it is I am doing wrong?

Regards
Priya

- Was this comment helpful? Yes / No Reply - Report abuse

xml_looser in Wiesbaden, Germany

63 months ago

Three way for explain the problem

I prefer the with

<xsl:template match="New_Product">

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

<xsl:template match="/">
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates select="root/New_Product"/>
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates select="root"/>
</xsl:template>

<xsl:template match="New_Product">

<xsl:choose>
<xsl:when test="text()=1">New&#xA;</xsl:when>
<xsl:otherwise>Old&#xA;</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="root">
<xsl:apply-templates select="New_Product"/>
<xsl:text>&#xA;</xsl:text>
<xsl:for-each select="*">

<xsl:choose>
<xsl:when test="local-name()='New_Product' and text()=1">New&#xA;</xsl:when>
<xsl:otherwise>Old&#xA;</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

- Was this comment helpful? Yes / No Reply - Report abuse

Priya9 in Auckland, New Zealand

63 months ago

xml_looser in Wiesbaden, Germany said: Three way for explain the problem

I prefer the with

<xsl:template match="New_Product">

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

<xsl:template match="/">
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates select="root/New_Product"/>
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates select="root"/>
</xsl:template>

<xsl:template match="New_Product">

<xsl:choose>
<xsl:when test="text()=1">New&#xA;</xsl:when>
<xsl:otherwise>Old&#xA;</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="root">
<xsl:apply-templates select="New_Product"/>
<xsl:text>&#xA;</xsl:text>
<xsl:for-each select="*">

<xsl:choose>
<xsl:when test="local-name()='New_Product' and text()=1">New&#xA;</xsl:when>
<xsl:otherwise>Old&#xA;</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Hi xml_looser

Thanks for your reply. I have solved the problem like this.

<xsl:choose>
<xsl:when test="./New_Product=1">New</xsl:when>
<xsl:otherwise>Old</xsl:otherwise>
</xsl:choose>

Regards
Priya

- Was this comment helpful? Yes / No Reply - Report abuse

» Sign in or create an account to comment on this topic.