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. Beginner XSL problem

Beginner XSL problem

Scheduled Pinned Locked Moved XML / XSL
xmlquestionregexhelplearning
3 Posts 2 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.
  • T Offline
    T Offline
    tomiga
    wrote on last edited by
    #1

    Welcome I have XML file: <doc> <field> <name> myName</name> <value> some value</value> </field> <field> <name> otherName</name> <value> other value</value> </field> </doc> I have created XSL file: <xsl:template match="/"> <!-- transform fields --> <xsl:for-each select="field"> <xsl:choose> <!-- i want get data from myName field --> <xsl:when test="cd[name='myName']"> <xsl:value-of select="value"/> <xsl:when> <xsl:choose> </xsl:for-each> </xsl:template> unfortunately it doesn't create output file as: some value What is wrong?

    M 1 Reply Last reply
    0
    • T tomiga

      Welcome I have XML file: <doc> <field> <name> myName</name> <value> some value</value> </field> <field> <name> otherName</name> <value> other value</value> </field> </doc> I have created XSL file: <xsl:template match="/"> <!-- transform fields --> <xsl:for-each select="field"> <xsl:choose> <!-- i want get data from myName field --> <xsl:when test="cd[name='myName']"> <xsl:value-of select="value"/> <xsl:when> <xsl:choose> </xsl:for-each> </xsl:template> unfortunately it doesn't create output file as: some value What is wrong?

      M Offline
      M Offline
      MS le Roux
      wrote on last edited by
      #2

      Change the select attribute of the xsl:for-each element to either "doc/field" or "//field". <field> is not the root element; it's a child element. Change the test attribute of the xsl:when element to contain the value "name=' myName'".

      T 1 Reply Last reply
      0
      • M MS le Roux

        Change the select attribute of the xsl:for-each element to either "doc/field" or "//field". <field> is not the root element; it's a child element. Change the test attribute of the xsl:when element to contain the value "name=' myName'".

        T Offline
        T Offline
        tomiga
        wrote on last edited by
        #3

        thx (there was no space in oryginal ;) but correct version of test shoud look like xsl:when test="name='myName'"

        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