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. wrong element in transformed xml

wrong element in transformed xml

Scheduled Pinned Locked Moved XML / XSL
xmlwpfregextutorialquestion
2 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.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    xml data

    <?xml version="1.0" ?>
    <statement>
    <accounts>
    <account number="22">
    <currency symbol="USD">
    <transactions>
    <transaction>
    <id>1</id>
    </transaction>
    </transactions>
    </currency>
    <currency symbol="EUR">
    <transactions>
    <transaction>
    <id>2</id>
    </transaction>
    </transactions>
    </currency>
    </account>
    </accounts>
    </statement>

    transformed with msxml parser using stylesheet

    <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" standalone="yes"/>
    <xsl:template match="/">
    <xsl:element name="VFPData">
    xsl:apply-templates/
    </xsl:element>
    </xsl:template>
    <xsl:template match="/statement/accounts/account/currency/transactions/*">
    <xsl:element name="result">
    <xsl:element name="id"><xsl:value-of select="id"/></xsl:element>
    <xsl:element name="currency"><xsl:value-of
    select="../../../currency/@symbol"/></xsl:element>
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

    produces

    <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
    <VFPData><result>
    <id>1</id>
    <currency>USD</currency>
    </result>
    <result><id>2</id>
    <currency>USD</currency>
    </result></VFPData>

    In this output currency element value for id 2 is wrong: it must be EUR How to change stylesheet so that EUR is in id 2 record ? Andrus.

    Andrus

    G 1 Reply Last reply
    0
    • A AndrusM

      xml data

      <?xml version="1.0" ?>
      <statement>
      <accounts>
      <account number="22">
      <currency symbol="USD">
      <transactions>
      <transaction>
      <id>1</id>
      </transaction>
      </transactions>
      </currency>
      <currency symbol="EUR">
      <transactions>
      <transaction>
      <id>2</id>
      </transaction>
      </transactions>
      </currency>
      </account>
      </accounts>
      </statement>

      transformed with msxml parser using stylesheet

      <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" standalone="yes"/>
      <xsl:template match="/">
      <xsl:element name="VFPData">
      xsl:apply-templates/
      </xsl:element>
      </xsl:template>
      <xsl:template match="/statement/accounts/account/currency/transactions/*">
      <xsl:element name="result">
      <xsl:element name="id"><xsl:value-of select="id"/></xsl:element>
      <xsl:element name="currency"><xsl:value-of
      select="../../../currency/@symbol"/></xsl:element>
      </xsl:element>
      </xsl:template>
      </xsl:stylesheet>

      produces

      <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
      <VFPData><result>
      <id>1</id>
      <currency>USD</currency>
      </result>
      <result><id>2</id>
      <currency>USD</currency>
      </result></VFPData>

      In this output currency element value for id 2 is wrong: it must be EUR How to change stylesheet so that EUR is in id 2 record ? Andrus.

      Andrus

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      I believe you just need to change this line: "../../../currency/@symbol" to this: "../../@symbol"

      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