Question Locked

XSL Transform in .NET?

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
I am using an xsl stylesheet to transform a xml file (an iPod library plist to xml code that my app can handle). I have succesfully applied the transform in VB.NET using an Xsl.XslCompiledTransform object, and this results in an xml file that I can successfully use with my app. My problem is this, all the values return to the new xml file are string values, I require the numbers to be numbers, strings to be strings. I havein my xslt file applied a test to the value thus:

xsl:when test="number(following-sibling::node()[1]) = following-sibling::node()[1]"
xsl:value-of select="number(following-sibling::node()[1])"/
/xsl:when
xsl:otherwise
xsl:value-of select="following-sibling::node()[1]"/
/xsl:otherwise

this successfully finds number formated values, but the resulting xml file still returns all string values. Does anyone have any pointers? I have virtually no xml knowledge.
Thanks in advance.

4 replies

by soundbomber

OK so it seems that all xml attributes are returned as string values, so I will find another way round!

by tony hopkinson

, if you want to treat some of it as numbers, you have to convert it.

There are a few ways to do that.
You can serialise / deserialise to an object. Net will do that for you, though there are some limits and rules, and after simple structures a good bit of cacking about.

You can create a schema to describe the xml. That can be typed. Then you can either use it in code, or use the Data source wizrd thingy.

Last and almost certainly least you can hard code
Int32 MyNumber = Convert.ToInt32(SomeXmlNode.InnertText);

Given of course the node does contain a number, and of course the XmlNode isn't null....

If it's one off, you could get away with that but it's about as comfortable to reuse as someone else's suppository. :(

by soundbomber

Thanks Tony, that has answered my question AND put a rather unpleasant picture in my head!!! :0

This discussion is closed to new replies.