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. Namespace Parsing Problem

Namespace Parsing Problem

Scheduled Pinned Locked Moved XML / XSL
xmlquestioncombeta-testingregex
4 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    sdsuzuki
    wrote on last edited by
    #1

    I’m new to XSL and struggling with this for awhile. Hope someone can take a look at my code and provide me with your feedback. The output looks close to what I want, but it’s not quite there yet. I’m looking for certain attributes (id=GUIDs) in ‘task’ element and copy the entire ‘task’ element if the attribute is matched with what I’m looking for. However the namespace cannot be copied correctly. Basically I don’t want the output to have the reference “:det” in taskGroup element and xmlns=http://schemas... in task element. How do I do this? Please see the source xml, xsl, current incorrect output and expected output below. Thank you in advance! Source XML:

    <?xml version="1.0" encoding="utf-8"?>
    <taskGroup revocation="false" taskGroupGuid="{a0949a60-006c-4b35-b334-97ca289b06cd}" xmlns="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks">
    <tasks>
    <task id="{f418cae0-6b68-409b-93f4-a19fa1a5faad}" rank="2" name="1" description="2" tooltip="2" >
    <command type="ShellExecute">
    <arguments>
    <commandLine>www.xxxxxx.com</commandLine>
    </arguments>
    </command>
    </task>
    <task id="{91395410-c164-468c-a247-14bbd7ceea88}" rank="5" issueTime="2009-09-15T11:05:42Z" requiresElevation="false" name="3" description="4" tooltip="4" >
    <command type="ShellExecute">
    <arguments>
    <commandLine>www.yyyyyy.com</commandLine>
    </arguments>
    </command>
    </task>
    </tasks>
    </taskGroup>
    ...
    ...
    ...

    XSL:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:det="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks"

    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
    <taskGroup revocation="false" taskGroupGuid="{{a0949a60-006c-4b35-b334-97ca289b06cd}}" >
    <xsl:call-template name="taskList"></xsl:call-template>
    </taskGroup>
    </xsl:template>
    <xsl:template name="taskList">
    <xsl:copy-of select="//det:task[@id='{91395410-c164-468c-a247-14bbd7ceea88}']"/>
    </xsl:template>
    </xsl:stylesheet>

    Current Output (incorrect):

    <?xml version="1.0" encoding="utf-8"?>
    <

    S S 2 Replies Last reply
    0
    • S sdsuzuki

      I’m new to XSL and struggling with this for awhile. Hope someone can take a look at my code and provide me with your feedback. The output looks close to what I want, but it’s not quite there yet. I’m looking for certain attributes (id=GUIDs) in ‘task’ element and copy the entire ‘task’ element if the attribute is matched with what I’m looking for. However the namespace cannot be copied correctly. Basically I don’t want the output to have the reference “:det” in taskGroup element and xmlns=http://schemas... in task element. How do I do this? Please see the source xml, xsl, current incorrect output and expected output below. Thank you in advance! Source XML:

      <?xml version="1.0" encoding="utf-8"?>
      <taskGroup revocation="false" taskGroupGuid="{a0949a60-006c-4b35-b334-97ca289b06cd}" xmlns="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks">
      <tasks>
      <task id="{f418cae0-6b68-409b-93f4-a19fa1a5faad}" rank="2" name="1" description="2" tooltip="2" >
      <command type="ShellExecute">
      <arguments>
      <commandLine>www.xxxxxx.com</commandLine>
      </arguments>
      </command>
      </task>
      <task id="{91395410-c164-468c-a247-14bbd7ceea88}" rank="5" issueTime="2009-09-15T11:05:42Z" requiresElevation="false" name="3" description="4" tooltip="4" >
      <command type="ShellExecute">
      <arguments>
      <commandLine>www.yyyyyy.com</commandLine>
      </arguments>
      </command>
      </task>
      </tasks>
      </taskGroup>
      ...
      ...
      ...

      XSL:

      <?xml version="1.0" encoding="utf-8"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:det="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks"

      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="/">
      <taskGroup revocation="false" taskGroupGuid="{{a0949a60-006c-4b35-b334-97ca289b06cd}}" >
      <xsl:call-template name="taskList"></xsl:call-template>
      </taskGroup>
      </xsl:template>
      <xsl:template name="taskList">
      <xsl:copy-of select="//det:task[@id='{91395410-c164-468c-a247-14bbd7ceea88}']"/>
      </xsl:template>
      </xsl:stylesheet>

      Current Output (incorrect):

      <?xml version="1.0" encoding="utf-8"?>
      <

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      You have to have the namespace declaration somewhere/somehow - the task element in the output has been copied verbatim from the input, where it lived in the det/http://schemas.microsoft.com/windows/2008/deviceExperienceTasks namespace. What output do you WANT to see?

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      1 Reply Last reply
      0
      • S sdsuzuki

        I’m new to XSL and struggling with this for awhile. Hope someone can take a look at my code and provide me with your feedback. The output looks close to what I want, but it’s not quite there yet. I’m looking for certain attributes (id=GUIDs) in ‘task’ element and copy the entire ‘task’ element if the attribute is matched with what I’m looking for. However the namespace cannot be copied correctly. Basically I don’t want the output to have the reference “:det” in taskGroup element and xmlns=http://schemas... in task element. How do I do this? Please see the source xml, xsl, current incorrect output and expected output below. Thank you in advance! Source XML:

        <?xml version="1.0" encoding="utf-8"?>
        <taskGroup revocation="false" taskGroupGuid="{a0949a60-006c-4b35-b334-97ca289b06cd}" xmlns="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks">
        <tasks>
        <task id="{f418cae0-6b68-409b-93f4-a19fa1a5faad}" rank="2" name="1" description="2" tooltip="2" >
        <command type="ShellExecute">
        <arguments>
        <commandLine>www.xxxxxx.com</commandLine>
        </arguments>
        </command>
        </task>
        <task id="{91395410-c164-468c-a247-14bbd7ceea88}" rank="5" issueTime="2009-09-15T11:05:42Z" requiresElevation="false" name="3" description="4" tooltip="4" >
        <command type="ShellExecute">
        <arguments>
        <commandLine>www.yyyyyy.com</commandLine>
        </arguments>
        </command>
        </task>
        </tasks>
        </taskGroup>
        ...
        ...
        ...

        XSL:

        <?xml version="1.0" encoding="utf-8"?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:det="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks"

        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
        <taskGroup revocation="false" taskGroupGuid="{{a0949a60-006c-4b35-b334-97ca289b06cd}}" >
        <xsl:call-template name="taskList"></xsl:call-template>
        </taskGroup>
        </xsl:template>
        <xsl:template name="taskList">
        <xsl:copy-of select="//det:task[@id='{91395410-c164-468c-a247-14bbd7ceea88}']"/>
        </xsl:template>
        </xsl:stylesheet>

        Current Output (incorrect):

        <?xml version="1.0" encoding="utf-8"?>
        <

        S Offline
        S Offline
        sdsuzuki
        wrote on last edited by
        #3

        I used a namespace reference ":det" in the xls ("xmlns:det="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks"), but I want to see the namespace in the output without the reference. There is also extra namespace appears in the end of the 'task' element which I don't want.

        S 1 Reply Last reply
        0
        • S sdsuzuki

          I used a namespace reference ":det" in the xls ("xmlns:det="http://schemas.microsoft.com/windows/2008/deviceExperienceTasks"), but I want to see the namespace in the output without the reference. There is also extra namespace appears in the end of the 'task' element which I don't want.

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Why does it make any difference? Semantically, both forms are exactly the same.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          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