473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

.net framework XSLT processor appears to be broken

I stumbled upon this while developing a custom XPathNavigator.
It appears that copy action for attributes is broken in the .net
framework XSLT processor.

The intent was to just copy the entities and attributes from the
source XML into the output using simple "identity" like XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

This appears to loose the attributes of non-leaf entities when run
over a custom XPathNavigator. The problem appears to be related to the
order of processing. When run over a custom XPathNavigator the child
entities are processed before the attributes in the above XSLT.

The situation can be recreated over a regular XmlDocument using
following XSLT:

This does not work (notice the order of processing - attributes are
processed first):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*|/">
<xsl:copy>
<xsl:apply-templates select="*" />
<xsl:apply-templates select="@*" />
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>

This does work (notice the order of processing - attributes are
processed first)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*|/">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>

Here is a quick and dirty code snippet:
---------------------------------------------------------
String xsltFileName = "test.xslt";
XmlReader transfromReader = new XmlTextReader(xsltFileName);

XslTransform transform = new XslTransform();
transform.Load(transfromReader);

StringBuilder result = new StringBuilder();
TextWriter writer = new StringWriter(result);

String xmltestFileName = "test.xml";
XmlDocument testDocument = new XmlDocument();
testDocument.Load(xmltestFileName);

transform.Transform(testDocument,null,writer);
---------------------------------------------------------

Any XML document with several levels of entity nesting and some
attributes at each level can be used to recreate the situation.
Nov 12 '05 #1
3 1719
Alex wrote:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net
framework XSLT processor.

The intent was to just copy the entities and attributes from the
source XML into the output using simple "identity" like XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

This appears to loose the attributes of non-leaf entities when run
over a custom XPathNavigator. The problem appears to be related to the
order of processing. When run over a custom XPathNavigator the child
entities are processed before the attributes in the above XSLT.
Well, it works for me (and always worked). Apparently the problem is
with your custom XPathNavigator? Provide more information about it.
The situation can be recreated over a regular XmlDocument using
following XSLT:

This does not work (notice the order of processing - attributes are
processed first):

You meant attributes are processed after elements. This shouldn't work
according to the XSLT spec. Attributes must be processed before child
nodes. Identity transformatio assures it by using
<xsl:apply-templates select="@* | node()"/>
Here xsl:apply-templates instruction processes selected nodes in
document order and attributes go before child nodes in document order by
definition.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Thank you for the reply.
Well, it works for me (and always worked). Apparently the problem is
with your custom XPathNavigator? Provide more information about it.
A custom XPathNavigator does not have any real ability to influence
the
order of processing (attributes vs. child elements). In my case the
XPathNavigator exposes a very complex repository as virtual XML...

The navigator only implements the minimum set of necessary functions
like MoveNext(), etc. It does not implement any custom XPath engine,
etc.

What I observe is that in the case of Identity transformation the
attributes
are processed after the child elements when transforming my
XPathNavigator.

However when the same transformation is used to transform a
XmlDocument
it processes the attributes first.

You meant attributes are processed after elements. This shouldn't workaccording to the XSLT spec. Attributes must be processed before child
nodes. Identity transformatio assures it by using
<xsl:apply-templates select="@* | node()"/>
Here xsl:apply-templates instruction processes selected nodes in
document order and attributes go before child nodes in document order bydefinition.

Nov 12 '05 #3
Alex wrote:
A custom XPathNavigator does not have any real ability to influence
the
order of processing (attributes vs. child elements). In my case the
XPathNavigator exposes a very complex repository as virtual XML...

The navigator only implements the minimum set of necessary functions
like MoveNext(), etc. It does not implement any custom XPath engine,
etc.
Hmmm, you are right. I wonder how the problem can be traced. Can you
dump a sequence of calls to your XPathNavigator? Try to debug it to see
how it gets moved, sometimes weird things might happen just because of a
single forgotten Clone() call.
What I observe is that in the case of Identity transformation the
attributes
are processed after the child elements when transforming my
XPathNavigator.


Try modified identity transformation to find out where the problem is:

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4

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

Similar topics

1
by: Doug Farrell | last post by:
Hi all, I'm trying to use the 4Suite xml/xsl tools to transform some XML data into HTML. I'm using some examples from the O'Reilly book "Python and XML" and things are blowing up. Here is the...
8
by: Ola Natvig | last post by:
Anybody out there who knows if the 4suite implementation of XSLT are a threadsafe one? -- -------------------------------------- Ola Natvig <ola.natvig@infosense.no> infoSense AS / development
1
by: Ola Natvig | last post by:
Hi all I'm working with a long running, threaded server which serves HTTP requests with content which are passed through a XSLT processor. The XSLT processor I'm using is the Pyana processor. ...
1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
7
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet...
10
by: daz_oldham | last post by:
Hi I am doing an XSLT that processes (for example) a list of hotels. Each hotel has the attribute @StarRating which is one of the following values: * ** *** ****
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
7
by: Zzzbla | last post by:
Hi all, anyone has a live example of loading an xml file from a server, an xslt file from the server, then transforming the xml using the xslt and outputing the results (preferably with...
4
by: =?Utf-8?B?REZC?= | last post by:
Within an XSLT transformation, I'm trying to switch the default namespace within a section of the generated XML document to a shared namespace. This way, the content of this section does not have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.