473,513 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xslt transform not working in .net that works in msxml

Hello Group,

I am just about tearing my hair out with this one and thought someone may
have some insight. I have a transform that wasn't working so I grabbed the
nearest debugger (xselerator) and saw that it works just fine. Now what I
mean by not working is that it just silently fails to produce the expected
output... no exceptions are being thrown. Xselerator uses msxml 3 so it's
not really helping me see the problem in .net 1.1.

Given the following xml:

<navitem title="Main" level="0">
<navitem title='Welcome' link='someurl.aspx' level="1" ></navitem>
<navitem title='Welcome' link='someurl.aspx' level="1"></navitem>
<navitem title='Welcome' link='someurl.aspx' level="1"></navitem>
<navitem title='Welcome' link='someurl.aspx' level="1">
<navitem title='Welcome' link='someurl.aspx' level="2"></navitem>
<navitem title='Welcome' link='someurl.aspx' level="2"></navitem>
</navitem>
</navitem>

and the following xslt:

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

<xsl:template match="/">
<navitems>
<xsl:apply-templates select="navitem" />
</navitems>
</xsl:template>

<xsl:template match="navitem">
<xsl:choose>
<xsl:when test="number(@level) &gt; 0">
<xsl:element name="navitem">
<xsl:attribute name="title"><xsl:value-of select="@title"
/></xsl:attribute>
<xsl:attribute name="link"><xsl:value-of select="@url"
/></xsl:attribute>
<xsl:apply-templates select="navitem" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="navitem" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

All i will get will be: <navitems></navitems> with system.xml . With the
debugger that uses msxml 3 I get my expected result tree that includes all
elements but those with a level less than 1.

Anyone see a flaw in something I am doing that system.xml doesn't like?

Regards,
Jason S.
Nov 12 '05 #1
3 2453
"Jason S" <so*****@somewhere.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
I am just about tearing my hair out with this one and thought someone may
have some insight. I have a transform that wasn't working so I grabbed the
nearest debugger (xselerator) and saw that it works just fine. Now what I
mean by not working is that it just silently fails to produce the expected
output...


Jason,

To add to your impending baldness problem ;-), I just tried running your .xml and
..xsl through the following [trivial] test project,

public static void Main( )
{
XmlDocument doc = new XmlDocument( );
doc.Load( "nav.xml");
XslTransform xsl = new XslTransform( );
xsl.Load( "nav.xsl");
xsl.Transform( doc.CreateNavigator( ), null, new XmlTextWriter( Console.Out));
}

and it works just fine for me, although the link attributes are empty because your .xsl is using
a <xsl:value-of select='@url' /> when the .xml document contains link attributes (not url).

What code are you using the execute the transformation with in your application, perhaps the
fault is there?
Derek Harmon
Nov 12 '05 #2
That's wild. I never thought to check the code that I was using to call the
transform because it was working with some other transforms. Here is the
code I use now in an aspx code behind class to do the transform (nodWorking
is a node that contains the fragment that I want to work with):

XPathNavigator xpn = nodWorking.CreateNavigator();
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);

XslTransform xslt = new XslTransform();
xslt.Load(MapPathsitemaptonav.xslt"));
xslt.Transform(xpn, null, xtw, null);

return sw.ToString().Replace("\"", "\\'");

The transform works but all I get is what matches the root template... all I
get back is <navitems></navitems>. Sorry about the discrepancy in
attributes, that sample was taken from an earlier file... the real one uses
url. If you see anything out of the ordinary in this code my scalp
appreciates it :o)

Regards,
Jason

"Derek Harmon" <lo*******@msn.com> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
"Jason S" <so*****@somewhere.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator) and saw that it works just fine. Now what I mean by not working is that it just silently fails to produce the expected output...


Jason,

To add to your impending baldness problem ;-), I just tried running your

..xml and .xsl through the following [trivial] test project,

public static void Main( )
{
XmlDocument doc = new XmlDocument( );
doc.Load( "nav.xml");
XslTransform xsl = new XslTransform( );
xsl.Load( "nav.xsl");
xsl.Transform( doc.CreateNavigator( ), null, new XmlTextWriter( Console.Out)); }

and it works just fine for me, although the link attributes are empty because your .xsl is using a <xsl:value-of select='@url' /> when the .xml document contains link attributes (not url).
What code are you using the execute the transformation with in your application, perhaps the fault is there?
Derek Harmon

Nov 12 '05 #3
I solved this. It turned out to be very hard to pin down but after long
research I learned [1] that when a transform is started it moves its
internal pointer to the root of the document. Well... LA DEE FRICKIN DAA!

This was crucial, as I was moving to node in an xml document that I wanted
to start the transformation at and was simply doing a CreateNavigator on
that node. Needless to say this was about as effective as napalm dousing a
fire... it just navigated itself back up to the document element. This is
mentioned NOWHERE.

Now, this appears in line with W3C standards but IMO it's extremely
misleading to be able to create an xpathnavigator on any node. Geesh.

Jason

[1]
http://www.google.com/groups?hl=en&l...%40tkmsftngp11

"Jason S" <so*****@somewhere.com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
That's wild. I never thought to check the code that I was using to call the transform because it was working with some other transforms. Here is the
code I use now in an aspx code behind class to do the transform (nodWorking is a node that contains the fragment that I want to work with):

XPathNavigator xpn = nodWorking.CreateNavigator();
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);

XslTransform xslt = new XslTransform();
xslt.Load(MapPathsitemaptonav.xslt"));
xslt.Transform(xpn, null, xtw, null);

return sw.ToString().Replace("\"", "\\'");

The transform works but all I get is what matches the root template... all I get back is <navitems></navitems>. Sorry about the discrepancy in
attributes, that sample was taken from an earlier file... the real one uses url. If you see anything out of the ordinary in this code my scalp
appreciates it :o)

Regards,
Jason

"Derek Harmon" <lo*******@msn.com> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
"Jason S" <so*****@somewhere.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I
grabbed the nearest debugger (xselerator) and saw that it works just fine. Now
what
I mean by not working is that it just silently fails to produce the expected output...
Jason,

To add to your impending baldness problem ;-), I just tried running

your .xml and
.xsl through the following [trivial] test project,

public static void Main( )
{
XmlDocument doc = new XmlDocument( );
doc.Load( "nav.xml");
XslTransform xsl = new XslTransform( );
xsl.Load( "nav.xsl");
xsl.Transform( doc.CreateNavigator( ), null, new XmlTextWriter(

Console.Out));
}

and it works just fine for me, although the link attributes are empty

because your .xsl is using
a <xsl:value-of select='@url' /> when the .xml document contains link

attributes (not url).

What code are you using the execute the transformation with in your

application, perhaps the
fault is there?
Derek Harmon


Nov 12 '05 #4

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

Similar topics

3
2868
by: Philipp Lenssen | last post by:
I have this XML file which I would like to XSLT-sort based on the string contained within the item-children elements using basic MSXML (no recent version of IIS, so it might be an outdated MSXML --...
7
4102
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...
2
1623
by: FrankStallone | last post by:
I am just getting started in XML and I made my first xml, dtd and xslt file and XML spy said they were all valid and they worked. This was the xslt doc that worked. <?xml version="1.0"...
3
9899
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
12
2877
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
8
2065
by: toby989 | last post by:
Hi All I am completely new to this, but I was wondering if I can apply 2 xslt's subsequently to an xml, via the (client side) scripting method: http://www.w3schools.com/xsl/xsl_client.asp ...
21
2506
by: Damian | last post by:
Hi, I'm from an ASP.NET background an am considering making the switch to Python. I decided to develop my next project in tandem to test the waters and everything is working well, loving the...
6
2637
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a...
3
2471
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I have some XML I want to display in a section of a web page. I want the XML displayed as a tree. The way you see XML if you load the file in the browser. It shows the tree and you can...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.