Forum Moderators: open

Message Too Old, No Replies

Getting the text value of an XML node

without it's children, using XSL.

         

joshie76

1:19 pm on Jan 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure if this is the correct place to post this but I know Xoc is fairly clued up on his XSL.

This is probably a really dumb question but.... How do I get the node text value of /testxml (see below) without getting the text value of any child nodes (testnode) using XPATH and XSLT?

<?xml version="1.0"?>
<testxml>
testxmlvalue
<testnode>
testnodevalue
</testnode>
</testxml>

Dreamquick

1:59 pm on Jan 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I was using merely XPATH (sorry not much XSL experience) to search the text from that node I'd use;

//testxml[ text() = "testxmlvalue"]

Do you have access to the text() selector via XSL / does it work in a similar fashion...

- Tony

BlobFisk

2:03 pm on Jan 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In xpath //testxml will return only testxml values.

XSLT is a bit more tricky, XSLT is a transformation language so I'd suggest that you use the same xpath pattern to lactate the tag and apply an appropriate template.

Not sure if this answers your question!

I always check out my xpath patterns on this site. It's quite good for a quick test:
[perfectxml.com...]

I hope that this answers your question! My XML is still very very raw!

joshie76

2:20 pm on Jan 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup, the text() function is the baby!

In XSLT it would be used like so

<xsl:value-of select="/text()"/>

It's not in the MSXML documentation we have but a colleague just found it by guessing lots of different function names.

Thanks anyway.

duckhunter

2:50 am on Jan 15, 2003 (gmt 0)

10+ Year Member



For all practical purposes, that's not good XML design. You should wrap datapoints in their own tag.

joshie76

9:02 am on Jan 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hear this a lot but there are lots of XML standards out there that use this format and it is, after all, valid XML.

I'm actually looking at transforming XHTML documents which (obviously) use this type of structure heavily.

duckhunter

3:21 am on Jan 16, 2003 (gmt 0)

10+ Year Member



Sure, and I can even agree to some uses for it, but it does create some of the problems you are addressing here.

I just spent a good bit of time pouring over the local variable stack when I load up that XML and I can't find a property (out of hundreds) that contains just "testxmlvalue" as it's value. The properties always contain the rest of the NODE.

Realize, you are asking for the TEXT value of an XML NODE that contains more than just the word "testxmlvalue". It also contains more text (XML formatted but it is the string representation of what is inside the tag <testxml>.