472,958 Members | 2,151 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.

.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 1702
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: 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...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
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 :...
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...
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...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.