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. XSL: how to properly reference to xml field?

XSL: how to properly reference to xml field?

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

    I'm looking for a way to properly set xsl:match="..." or xsl:value-of select="..." My files are: test.xsl

    <?xml version="1.0" encoding="Windows-1250"?>

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <!--<xsl:template match="DocumentContent/section[@name]">-->
    <html>
    <head>
    <!-- <link rel="stylesheet" href="zastyles.css"/> -->
    </head>
    <body>
    <h2>SingleRow1</h2>
    <table border="1px" bgcolor="yellow">
    <tr>
    <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldA"/>
    </td>
    <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldB"/>
    </td>
    <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldC"/>
    </td>
    <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldD"/>
    </td>
    </tr>
    </table>
    <br/>
    <h2>SingleRow2</h2>
    <table border="1px" bgcolor="yellow">
    <tr>
    <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldA"/>
    </td>
    <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldB"/>
    </td>
    <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldC"/>
    </td>
    <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldD"/>
    </td>
    </tr>
    </table>
    <h2>MulitRow1</h2>
    <table border="1px" bgcolor="lightgreen">
    <xsl:for-each select="DocumentContent/section['MultiRow1']/row">
    <tr>
    <td><xsl:value

    Richard DeemingR 1 Reply Last reply
    0
    • M Maciej Los

      I'm looking for a way to properly set xsl:match="..." or xsl:value-of select="..." My files are: test.xsl

      <?xml version="1.0" encoding="Windows-1250"?>

      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
      <!--<xsl:template match="DocumentContent/section[@name]">-->
      <html>
      <head>
      <!-- <link rel="stylesheet" href="zastyles.css"/> -->
      </head>
      <body>
      <h2>SingleRow1</h2>
      <table border="1px" bgcolor="yellow">
      <tr>
      <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldA"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldB"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldC"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section['SingleRow1']/row/FieldD"/>
      </td>
      </tr>
      </table>
      <br/>
      <h2>SingleRow2</h2>
      <table border="1px" bgcolor="yellow">
      <tr>
      <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldA"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldB"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldC"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section['SingleRow2']/row/FieldD"/>
      </td>
      </tr>
      </table>
      <h2>MulitRow1</h2>
      <table border="1px" bgcolor="lightgreen">
      <xsl:for-each select="DocumentContent/section['MultiRow1']/row">
      <tr>
      <td><xsl:value

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You can't just use the value of an attribute on the node as an indexer into the collection of nodes. You need to specify the attribute name and a comparison operator: DocumentContent/section[@name = 'SingleRow1']/row/FieldA Your current XSL is matching every <section> node, which is why you're getting two blank lines at the start of your <xsl:for-each> block - one for "SingleRow1", and one for "SingleRow2".

      <?xml version="1.0" encoding="Windows-1250"?>

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
      <!--<xsl:template match="DocumentContent/section[@name]">-->
      <html>
      <head>
      <!-- <link rel="stylesheet" href="zastyles.css"/> -->
      </head>
      <body>
      <h2>SingleRow1</h2>
      <table border="1px" bgcolor="yellow">
      <tr>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldA"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldB"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldC"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldD"/>
      </td>
      </tr>
      </table>
      <br/>
      <h2>SingleRow2</h2>
      <table border="1px" bgcolor="yellow">
      <tr>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow2']/row/FieldA"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow2']/row/FieldB"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow2']/row/FieldC"/>
      </td>
      <td><xsl:value-of select="DocumentContent/section[@name

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        You can't just use the value of an attribute on the node as an indexer into the collection of nodes. You need to specify the attribute name and a comparison operator: DocumentContent/section[@name = 'SingleRow1']/row/FieldA Your current XSL is matching every <section> node, which is why you're getting two blank lines at the start of your <xsl:for-each> block - one for "SingleRow1", and one for "SingleRow2".

        <?xml version="1.0" encoding="Windows-1250"?>

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
        <!--<xsl:template match="DocumentContent/section[@name]">-->
        <html>
        <head>
        <!-- <link rel="stylesheet" href="zastyles.css"/> -->
        </head>
        <body>
        <h2>SingleRow1</h2>
        <table border="1px" bgcolor="yellow">
        <tr>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldA"/>
        </td>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldB"/>
        </td>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldC"/>
        </td>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow1']/row/FieldD"/>
        </td>
        </tr>
        </table>
        <br/>
        <h2>SingleRow2</h2>
        <table border="1px" bgcolor="yellow">
        <tr>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow2']/row/FieldA"/>
        </td>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow2']/row/FieldB"/>
        </td>
        <td><xsl:value-of select="DocumentContent/section[@name = 'SingleRow2']/row/FieldC"/>
        </td>
        <td><xsl:value-of select="DocumentContent/section[@name

        M Offline
        M Offline
        Maciej Los
        wrote on last edited by
        #3

        Thank you, Richard so much ;) Last few days i was struggle with it section[@thankyou='thank you']

        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