By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

xslt transform not working in .net that works in msxml

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.