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. Getting XML content

Getting XML content

Scheduled Pinned Locked Moved XML / XSL
xmlhtmlcomtutorialquestion
3 Posts 2 Posters 7 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
    stevenykl
    wrote on last edited by
    #1

    Hello mates, I am new to XSL and would like to transform a NewML G2 format XML into another XML. For example I have:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!--

    • Structure: NML2 SNI Text
      -->
      <!-- ========================================================= -->
      <newsMessage xmlns="http://iptc.org/std/nar/2006-10-01/" xmlns:rtr="http://www.reuters.com/ns/2003/08/content" xmlns:x="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <header>
      <transmitId>tag:123.com,0000:newsml_N19279043:609406403</transmitId>
      <priority>3</priority>
      <destination>ABX</destination>
      </header>
      <itemSet>
      <newsItem conformance="power" guid="tag:reuters.com,0000:newsml_N19279043" standard="NewsML-G2" standardversion="2.1" version="609406403" xml:lang="en">
      <itemMeta>
      <itemClass qcode="icls:text" rtr:msgType="S"/>
      <provider literal="reuters.com"/>
      <versionCreated>2011-05-20T05:00:27.000Z</versionCreated>
      </itemMeta>
      <contentMeta>
      <urgency>3</urgency>
      <infoSource literal="Reuters" role="cRole:origProv"/>
      <subject qcode="N2:BNK"/>
      <headline>My Headline</headline>
      <by>ABC</by>
      </contentMeta>
      <contentSet>
      <inlineXML contenttype="application/xhtml+html" wordcount="881">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title/>
      </head>
      <body>
      <p>Paragraph A</p>
      <p>* Paragraph A</p>
      </body>
      </html>
      </inlineXML>
      </contentSet>
      </newsItem>
      </itemSet>
      </newsMessage>

    I would like my result XML to be something like:

    <?xml version="1.0" encoding="UTF-8"?>
    <MyData>
    <MyTransmitId>tag:123.com,0000:newsml_N19279043:609406403</MyTransmitId>
    <MyHeadline>My Headline</MyHeadline>
    <MyContent>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title/>
    </head>
    <body>
    <p>Paragraph A</p>
    <p>* Paragraph A&

    E 1 Reply Last reply
    0
    • S stevenykl

      Hello mates, I am new to XSL and would like to transform a NewML G2 format XML into another XML. For example I have:

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <!--

      • Structure: NML2 SNI Text
        -->
        <!-- ========================================================= -->
        <newsMessage xmlns="http://iptc.org/std/nar/2006-10-01/" xmlns:rtr="http://www.reuters.com/ns/2003/08/content" xmlns:x="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <header>
        <transmitId>tag:123.com,0000:newsml_N19279043:609406403</transmitId>
        <priority>3</priority>
        <destination>ABX</destination>
        </header>
        <itemSet>
        <newsItem conformance="power" guid="tag:reuters.com,0000:newsml_N19279043" standard="NewsML-G2" standardversion="2.1" version="609406403" xml:lang="en">
        <itemMeta>
        <itemClass qcode="icls:text" rtr:msgType="S"/>
        <provider literal="reuters.com"/>
        <versionCreated>2011-05-20T05:00:27.000Z</versionCreated>
        </itemMeta>
        <contentMeta>
        <urgency>3</urgency>
        <infoSource literal="Reuters" role="cRole:origProv"/>
        <subject qcode="N2:BNK"/>
        <headline>My Headline</headline>
        <by>ABC</by>
        </contentMeta>
        <contentSet>
        <inlineXML contenttype="application/xhtml+html" wordcount="881">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <title/>
        </head>
        <body>
        <p>Paragraph A</p>
        <p>* Paragraph A</p>
        </body>
        </html>
        </inlineXML>
        </contentSet>
        </newsItem>
        </itemSet>
        </newsMessage>

      I would like my result XML to be something like:

      <?xml version="1.0" encoding="UTF-8"?>
      <MyData>
      <MyTransmitId>tag:123.com,0000:newsml_N19279043:609406403</MyTransmitId>
      <MyHeadline>My Headline</MyHeadline>
      <MyContent>
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title/>
      </head>
      <body>
      <p>Paragraph A</p>
      <p>* Paragraph A&

      E Offline
      E Offline
      Erik Molenaar
      wrote on last edited by
      #2

      Hi, I would use the following stylesheet:

      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" media-type="text/html"/>
      <xsl:template match="/">
      <xsl:element name="MyData">
      <xsl:element name="MyTransmitId">
      <xsl:value-of select="//*[name()='transmitId']"/>
      </xsl:element>
      <xsl:element name="MyHeadline">
      <xsl:value-of select="//*[name()='headline']"/>
      </xsl:element>
      <xsl:element name="MyContent">
      <xsl:copy-of select="//*[name()='inlineXML']/*"/>
      </xsl:element>
      </xsl:element>
      </xsl:template>
      </xsl:stylesheet>

      I am not sure this is the best way, but it seems to generate the desired output Erik

      S 1 Reply Last reply
      0
      • E Erik Molenaar

        Hi, I would use the following stylesheet:

        <?xml version="1.0" encoding="UTF-8"?>
        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" media-type="text/html"/>
        <xsl:template match="/">
        <xsl:element name="MyData">
        <xsl:element name="MyTransmitId">
        <xsl:value-of select="//*[name()='transmitId']"/>
        </xsl:element>
        <xsl:element name="MyHeadline">
        <xsl:value-of select="//*[name()='headline']"/>
        </xsl:element>
        <xsl:element name="MyContent">
        <xsl:copy-of select="//*[name()='inlineXML']/*"/>
        </xsl:element>
        </xsl:element>
        </xsl:template>
        </xsl:stylesheet>

        I am not sure this is the best way, but it seems to generate the desired output Erik

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

        Thanks a lot Erik! This is exactly what I want. I happened to get another solution, I posted here for the benefits of others:

        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