472,958 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

XSLT "choose" incorrectly assigning the "Test"

hiya,
i have an xml doc, and I'd like to assign lookup values.
Eg, if the "PRODUCT-TYPE" is 6, then I insert "bike" into the innerText.

<code>
<rows>
<row>
<PRODUCT-TYPE>6</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2003</PRODUCT-DATE>
</row>
<row>
<PRODUCT-TYPE>7</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
</row>
</rows>
<code>
XSLT:
<code>
<xsl:for-each select="PRODUCT-TYPE">
<xsl:when test="@'PRODUCT-TYPE'">
<xsl:choose> <xsl:when test=".='6'">Bike</xsl:when>
<xsl:when test=".='7'">Car</xsl:when>
<xsl:when test=".='1'">Van</xsl:when>
<xsl:otherwise>UNDEFINED</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</code>

I get the error that "stylesheet wouldn't load".
Any ideas?I think that my syntax near the following lines might be wrong.

<xsl:for-each select="PRODUCT-TYPE">
<xsl:when test="@'PRODUCT-TYPE'">

Can anyone help offer a 2nd pair of eyes?

many thanks,
yogi

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #1
6 1345
chris yoker via DotNetMonster.com wrote:

<xsl:for-each select="PRODUCT-TYPE">
<xsl:when test="@'PRODUCT-TYPE'">


@'PRODUCT-TYPE' is syntactically incorrect XPath expression. What did
you mean in plain English?

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2
in English, i just meant:
"obtain the current value of current <PRODUCT-TYPE> node"

does this make sense?

yogi

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #3
chris yoker via DotNetMonster.com wrote:
in English, i just meant:
"obtain the current value of current <PRODUCT-TYPE> node"

does this make sense?


That's redundant. There is only one current node and at this point it's
always PRODUCT-TYPE element (because of xsl:for-each). xsl:when can be
used only within xsl:choice. And it's not clear where you want to obtain
the value too. In short - just get rid of that xsl:when.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #4
cheers Oleg
I've removed the "<xsl:when>"

my XSLT is now as follows:

<code>
<xsl:for-each select="PRODUCT-TYPE">
<xsl:choose>
<xsl:when test=".='6'">Bike</xsl:when>
<xsl:when test=".='7'">Car</xsl:when>
<xsl:when test=".='1'">Van</xsl:when>
<xsl:otherwise>UNDEFINED</xsl:otherwise>
</xsl:choose>
<xsl:copy-of select="." />
</xsl:for-each>
</code>

However, the output is incorrect.
<code>
<Rows>
<row>Bike<PRODUCT-TYPE>6</PRODUCT-TYPE><PRODUCT_DATE>30/03/2004</PRODUCT-
DATE></row>

//I've included blank lines for clarity.

<row>Car<PRODUCT-TYPE>7</PRODUCT-TYPE><PRODUCT_DATE>30/03/2004</PRODUCT-
DATE></row>
</code>
</Rows>

I want the transform to "overwrite the value "6" with the value "Bike" etc.
Ideally, the transform output would be:
<code>
<Rows>
<row>
<PRODUCT-TYPE>Bike</PRODUCT-TYPE>
<PRODUCT_DATE>30/03/2004</PRODUCT-DATE>
</row>
<row>
<PRODUCT-TYPE>Car</PRODUCT-TYPE>
<PRODUCT_DATE>30/03/2004</PRODUCT-DATE>
</row>
</code>
</Rows>

So, at this stage i've no idea where I am going wrong.
All help appreciated ;-)
ta,
yogi

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #5
chris yoker via DotNetMonster.com wrote:

I want the transform to "overwrite the value "6" with the value "Bike" etc.
Ideally, the transform output would be:
<code>
<Rows>
<row>
<PRODUCT-TYPE>Bike</PRODUCT-TYPE>
<PRODUCT_DATE>30/03/2004</PRODUCT-DATE>
</row>
<row>
<PRODUCT-TYPE>Car</PRODUCT-TYPE>
<PRODUCT_DATE>30/03/2004</PRODUCT-DATE>
</row>
</code>
</Rows>

So, at this stage i've no idea where I am going wrong.
All help appreciated ;-)


The simplest way of doing "keep all as is and change bits"
transformations is using identity transform rule:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="PRODUCT-TYPE">
<PRODUCT-TYPE>
<xsl:choose>
<xsl:when test=".='6'">Bike</xsl:when>
<xsl:when test=".='7'">Car</xsl:when>
<xsl:when test=".='1'">Van</xsl:when>
<xsl:otherwise>UNDEFINED</xsl:otherwise>
</xsl:choose>
</PRODUCT-TYPE>
</xsl:template>
</xsl:stylesheet>
--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #6
cheers Oleg,

My xslt was nowhere near as elegant.
I was calling a "rows" template then a "fields" template.

Thanks for the help.
yogi

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rupa | last post by:
Hi, I'm trying to write an xslt to convert an email in xml format to a new xml format. <descr> <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select> <xsl:when test=" <xsl:value-of...
3
by: David Walker | last post by:
Hi, I have an XML file created by a third party in which an element with a simple content model has a text value consisting of 2 parts separated by a colon, like this ...
1
by: nobody | last post by:
hi there! given <!ELEMENT a (#PCDATA | x)*> <!ELEMENT x (#PCDATA)> how can I find out if x is "embedded" at the beginning <a><x>xxx</x>aaa</a> or at the end <a>aaa<x>xxx</x></a> or in the...
1
by: Mark Richards | last post by:
The solutions for the following problems seems to be simple but I did not found a (convenient) solution: Assume we have a number of elements of the same type under a common parent e.g. <person...
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
1
by: kmunderwood | last post by:
I have an xml file that I get "As Is" (at bottom of post) I want to sort and exclude some elements, and turn other child elements red, or its background. I want it to look like this: Tank ...
1
by: chris yoker via DotNetMonster.com | last post by:
hiya, I'm still stuck at this one ;-( I want to overwrite the "numeric" value of my node with a lookup value. <xslt> <xsl:for-each select="PRODUCT-TYPE"> <xsl:choose> <xsl:when...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
2
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.