Start New Discussion within our Software Development Community

Hello guys I have an xslt file I want to extract data from.

I am new to xslt but at the moment I can perform basic operations like looping through the nodes and creating element and attributes.

My problem is that I want to select a particular value from a particular node(from a list of nodes), here is an example.

<PersonsList>

        <person>
                <id>1233</id>
                <name>john</name>
                </person>

                        <person>
                <id>444</id>
                <name>peter</name>
                </person>

                        <person>
                <id>677</id>
                <name>Amanda</name>
                </person>

        </PersonsList>

I want to get for example the name value say amanda if it matches the id. like in C# one would say: if (id==677) select name, Now I want the xslt equivalent.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="person">
    <xsl:if test="id = 677">
      <xsl:element name="Output">
        <xsl:value-of select="name"/>
      </xsl:element>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

As an example.

We would use the xsl:if to recreate the same if statement you demonstrated in c# :)

This article has been dead for over six months. Start a new discussion instead.