472,799 Members | 1,526 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,799 software developers and data experts.

xmlTransform transform <xsl:number> - possible Bug

Hi Group,

I think I have found a problem with the <xsl:element> when being
transformed by the .NET xmlTransform class. When using XmlSpy for
development and debugging, the <xsl:number> subsitutes the position of the
node correctly as I expected. This is fine with MSXML 3.0 & MSXML 4.0 plus
the XmlSpy internal engine.

I have been able to reproduce using a simpler Xml and Xsl to demonstrate;
XML
===
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head><title>Tester</title></head>
<body>
<h4 class="no">Table 1</h4>
<table><tbody><tr><td>Some Data</td></tr></tbody></table>
<h4 class="yes">Table 2</h4>
<table><tbody><tr><td>Some Data</td></tr><tr><td>Some Data
2</td></tr><tr><td>Some Data 3</td></tr></tbody>
</table>
<h4 class="yes">Table 3</h4>
<table><tbody><tr><td>Some Data</td></tr><tr><td>Some Data
2</td></tr><tr><td>Some Data 3</td></tr></tbody></table>
<h4 class="yes">Table 4</h4>
<table><tbody><tr><td>Some Data</td></tr><tr><td>Some Data
2</td></tr></tbody></table>
</body>
</html>

My XSL needs to return all rows that are in a table that has @class = 'yes'
and set an id attribute to the absolute position in the document - in
relation to all tables with @class = 'yes'.

XSL that achieves this
===============
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:element name="TableMatch">
<xsl:apply-templates select="//h4[@class='yes']" />
</xsl:element>
</xsl:template>
<xsl:template match="h4">
<xsl:element name="Table">
<xsl:for-each select="following-sibling::table[1]/tbody/tr">
<xsl:element name="row">
<xsl:attribute name="id">
<xsl:number level="any" from="//h4[@class='yes'][1]" />
</xsl:attribute>
<xsl:value-of select="td" />
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

This produces Output
==============
<?xml version="1.0" encoding="UTF-16"?>
<TableMatch>
<Table>
<row id="1">Some Data</row>
<row id="2">Some Data 2</row>
<row id="3">Some Data 3</row>
</Table>
<Table>
<row id="4">Some Data</row>
<row id="5">Some Data 2</row>
<row id="6">Some Data 3</row>
</Table>
<Table>
<row id="7">Some Data</row>
<row id="8">Some Data 2</row>
</Table>
</TableMatch>

Which is great! Now when I try the transformation using the following code
(C#);

public static void Main()
{
doc = new XPathDocument(inputFile); // Create New
XPath Document to open File
XPathNavigator navi = doc.CreateNavigator(); // Create
XPathNavigator to navigate through document

writer = new XmlTextWriter("xlsnumberOutput.xml" , Encoding.UTF8); //
Create new xmlTextWriter

// Now need to transform into Xml format
XslTransform transform = new XslTransform();
transform.Transform(doc, null, writer, new XmlUrlResolver());

// Kill Writer
writer.Flush();
writer.Close();
}

The <xsl:number> element is returning a blank string i.e. nothing and the
output is as follows;

<TableMatch>
<Table>
<row id="">Some Data</row>
<row id="">Some Data 2</row>
<row id="">Some Data 3</row>
</Table>
<Table>
<row id="">Some Data</row>
<row id="">Some Data 2</row>
<row id="">Some Data 3</row>
</Table>
<Table>
<row id="">Some Data</row>
<row id="">Some Data 2</row>
</Table>
</TableMatch>

@id is blank! The reason I want the @id in this way is because I want to
generate a unique identity across *all* matching rows. The .NET transform
has some problem achieving this.

Can anyone advise what the problem is here or some way of working around
this?

TIA (if you got this far :p)

b0yce
Nov 12 '05 #1
3 1902
<snip>

Can anyone advise what the problem is here or some way of working around
this?

TIA (if you got this far :p)

b0yce


Forgot to mention (pressed Send too early :) ) that I have narrowed it down
to the <xsl:number> from="" parameter.

Changing
<xsl:number level="any" from="//h4[@class='yes'][1]"/>
to
<xsl:number level="any" from="body"/>

now produces;
<?xml version="1.0" encoding="UTF-16"?>
<TableMatch>
<Table>
<row id="2">Some Data</row>
<row id="3">Some Data 2</row>
<row id="4">Some Data 3</row>
</Table>
<Table>
<row id="5">Some Data</row>
<row id="6">Some Data 2</row>
<row id="7">Some Data 3</row>
</Table>
<Table>
<row id="8">Some Data</row>
<row id="9">Some Data 2</row>
</Table>
</TableMatch>

in by all engines. Starting from 2 is not ideal since there could be n
number of tables @class='no' beforehand.

So it could be that in .NET XslTransform <xsl:number> doesn't like "//"
document root references?

Nov 12 '05 #2
Another time while playing around to get this to work, I changed the *from*
parameter again from "body" to "//h4[@class='yes']" (without the 1 indexer)
and it works, but the number is in relation to the ordinal position from the
current table and not the first table in the document - which is what I am
after. :(

So <xsl:number from="..."> works ok in MSXML 3.0 & 4.0 and in XML .NET. But
in the XML .NET it doesn't work when the @from parameter contains ordinal
position indexer. Seems strange.

???

b0yce

Forgot to mention (pressed Send too early :) ) that I have narrowed it down to the <xsl:number> from="" parameter.

Changing
<xsl:number level="any" from="//h4[@class='yes'][1]"/>
to
<xsl:number level="any" from="body"/>

now produces;
<?xml version="1.0" encoding="UTF-16"?>
<TableMatch>
<Table>
<row id="2">Some Data</row>
<row id="3">Some Data 2</row>
<row id="4">Some Data 3</row>
</Table>
<Table>
<row id="5">Some Data</row>
<row id="6">Some Data 2</row>
<row id="7">Some Data 3</row>
</Table>
<Table>
<row id="8">Some Data</row>
<row id="9">Some Data 2</row>
</Table>
</TableMatch>

in by all engines. Starting from 2 is not ideal since there could be n
number of tables @class='no' beforehand.

So it could be that in .NET XslTransform <xsl:number> doesn't like "//"
document root references?

Nov 12 '05 #3
I have managed to get this to work now in XML .NET.

One that don't work (only in XML .NET but fine in MSXML 3.0 and 4.0);

<xsl:number level="any" from="//H4[@class='yes'][1]" />

One that works in all versions;

<xsl:number level="any" from="//H4[@class='yes'][position()=1] />

I am surprised myself that I never tried this before, but I *always* use the
shorthand of [1] instead of [position() = 1] - just my lazy development
techniques ;).

The shorthand works in all but XML .NET version so I am not sure if this is
by design that it doesn't work or whether it is a slight oversight.
Eitherway I am happy I have found a solution.

So hopefully this will serve as some useful information for others out
there!

Enjoy

b0yce
Nov 12 '05 #4

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

Similar topics

0
by: johkar | last post by:
My XML and XSL is below. Also below is a textual representation of what I want to get out of the XML with XSL. For each Extension node in XML, I am only concerned with those nodes with...
3
by: Drulli Rokk | last post by:
Hi, Here's a question that has cost this newbie two days of headache already: How can I get my XSLT stylesheet to specify a maximum number of elements to process? I'm now using <xsl:for-each>...
29
by: Thomas | last post by:
Hi I have an XSL stylesheet: <xsl:for-each select="TRACKS/TRACK"> <tr class="TDL"> <td width="90%"><xsl:number value="position()" format="1" /> - <xsl:value-of select="TRACKTITLE"/></td>...
3
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function...
3
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion...
3
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been...
3
by: jariwaladivyesh | last post by:
Hi frnds, i have simple XML doc <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <data> <name> Divyesh Jariala</name> </data>
4
by: mark4asp | last post by:
I'm getting a problem with this code and I think the offending linke is : <xsl:if test="$folder = 'Search'"> I want to test the value of the Folder element for a value of precisely "Search"...
8
by: Hoi Wong | last post by:
With the XSLT 1.0 engine that I was forced to use, I have to parse old XML scripts where the number (to be parsed and saved into $EPISODE_NUMBER_RAW) that I want to parse is written with a comma...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.