calling all XML/XSL XPath gurus
-
This is a follow up on my "how do I do a join" question. I think I'm about to be screwed by .NET, because this is beginning to hurt so much. Here's the problem. I created a database schema and data using .NET's DataSet:
dataSet.WriteXml(fn, XmlWriteMode.WriteSchema);
And it dutifully creates an XML document, with the data looking like this (as an example): (BTW, how do you embed XML as source, so it doesn't get parsed, which is why all my example here have the opening '<' MISSING!!!):
PART>
ID>1001/ID>
PARTNUMBER>101045/PARTNUMBER>
DESC>FILTER, FUEL #2010SM RACOR/DESC>
/PART>
PART>
ID>1002/ID>
PARTNUMBER>101050/PARTNUMBER>
DESC>FILTER, #2020SM RACOR/DESC>
/PART>Now, I've got an XSL translation that looks something like this:
?xml version="1.0" encoding="UTF-8" ?>
xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
xsl:template match="/">
xsl:for-each select="//PART[@*]">
xsl:value-of select="ID"/>
xsl:value-of select="PARTNUMBER"/>
/xsl:for-each>
/xsl:template>
/xsl:stylesheet>as a test because it appears that fields like ID are not considered to be an attribute. (This select doesn't return any records, but a
//PART[not(@*)]
does return records. Instead, it seems that ID is an element (I hope I have my XPath terminology right here). So, when I actually do an XPath query like:xsl:for-each select="//PART[@ID='1001']">
I get no records back. Argh! :mad: Can I do this on the XML file that DataSet created??? Thanks a million! Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
-
This is a follow up on my "how do I do a join" question. I think I'm about to be screwed by .NET, because this is beginning to hurt so much. Here's the problem. I created a database schema and data using .NET's DataSet:
dataSet.WriteXml(fn, XmlWriteMode.WriteSchema);
And it dutifully creates an XML document, with the data looking like this (as an example): (BTW, how do you embed XML as source, so it doesn't get parsed, which is why all my example here have the opening '<' MISSING!!!):
PART>
ID>1001/ID>
PARTNUMBER>101045/PARTNUMBER>
DESC>FILTER, FUEL #2010SM RACOR/DESC>
/PART>
PART>
ID>1002/ID>
PARTNUMBER>101050/PARTNUMBER>
DESC>FILTER, #2020SM RACOR/DESC>
/PART>Now, I've got an XSL translation that looks something like this:
?xml version="1.0" encoding="UTF-8" ?>
xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
xsl:template match="/">
xsl:for-each select="//PART[@*]">
xsl:value-of select="ID"/>
xsl:value-of select="PARTNUMBER"/>
/xsl:for-each>
/xsl:template>
/xsl:stylesheet>as a test because it appears that fields like ID are not considered to be an attribute. (This select doesn't return any records, but a
//PART[not(@*)]
does return records. Instead, it seems that ID is an element (I hope I have my XPath terminology right here). So, when I actually do an XPath query like:xsl:for-each select="//PART[@ID='1001']">
I get no records back. Argh! :mad: Can I do this on the XML file that DataSet created??? Thanks a million! Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
You're right - you're currently looking for this <part id="1001"> Try //part[id='1001'] Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
You're right - you're currently looking for this <part id="1001"> Try //part[id='1001'] Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
IT WORKED! IT WORKED! WOOOHOOO! Thank you! :-D:-D:-D Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
-
IT WORKED! IT WORKED! WOOOHOOO! Thank you! :-D:-D:-D Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
You're welcome. As soon as you use the @, you're checking attributes, not nodes. Also, you can use text()= to check the value of the current node. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
This is a follow up on my "how do I do a join" question. I think I'm about to be screwed by .NET, because this is beginning to hurt so much. Here's the problem. I created a database schema and data using .NET's DataSet:
dataSet.WriteXml(fn, XmlWriteMode.WriteSchema);
And it dutifully creates an XML document, with the data looking like this (as an example): (BTW, how do you embed XML as source, so it doesn't get parsed, which is why all my example here have the opening '<' MISSING!!!):
PART>
ID>1001/ID>
PARTNUMBER>101045/PARTNUMBER>
DESC>FILTER, FUEL #2010SM RACOR/DESC>
/PART>
PART>
ID>1002/ID>
PARTNUMBER>101050/PARTNUMBER>
DESC>FILTER, #2020SM RACOR/DESC>
/PART>Now, I've got an XSL translation that looks something like this:
?xml version="1.0" encoding="UTF-8" ?>
xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
xsl:template match="/">
xsl:for-each select="//PART[@*]">
xsl:value-of select="ID"/>
xsl:value-of select="PARTNUMBER"/>
/xsl:for-each>
/xsl:template>
/xsl:stylesheet>as a test because it appears that fields like ID are not considered to be an attribute. (This select doesn't return any records, but a
//PART[not(@*)]
does return records. Instead, it seems that ID is an element (I hope I have my XPath terminology right here). So, when I actually do an XPath query like:xsl:for-each select="//PART[@ID='1001']">
I get no records back. Argh! :mad: Can I do this on the XML file that DataSet created??? Thanks a million! Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
Marc Clifton wrote: BTW, how do you embed XML as source, so it doesn't get parsed Check the "Display this message as-is (no HTML)" checkbox before submitting the post. --Mike-- "I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm