Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. calling all XML/XSL XPath gurus

calling all XML/XSL XPath gurus

Scheduled Pinned Locked Moved XML / XSL
xmldatabasequestionhelpcsharp
5 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    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.

    C M 2 Replies Last reply
    0
    • M Marc Clifton

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • C Christian Graus

        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

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #3

        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.

        C 1 Reply Last reply
        0
        • M Marc Clifton

          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.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • M Marc Clifton

            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.

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups