I have a simple xml file that is a list of attributes (Name/Value pairs):
<?xml version="1.0" encoding="ISO-8859-1"?>
<Attrs>
<Attr N="IsValid" V="true" />
<Attr N="ID" V="99099" />
</Attrs>
I want to create an XSLT file that outputs the values but I cant seem to get it to return the Value for the attribute
Here is my xslt:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Attrs">
<xsl:if test="Attr[@N='IsValid']">
--found IsValid
IsValid 1: <xsl:value-of select="current()/Attr[@V]"/>
IsValid 2: <xsl:value-of select="Attr[@V]"/>
</xsl:if>
<xsl:if test="Attr[@N='ID']">
--found ID
ID 1: <xsl:value-of select="current()/Attr[@V]"/>
ID 2: <xsl:value-of select="Attr[@V]"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
I simply cannot get the value of the 'V' attribute after finding the appropriate attribute Name (N='name'). I do not know how to select the @V value.
Here is my output:
<?xml version="1.0" encoding="utf-8"?>
--found IsValid
IsValid 1:
IsValid 2:
--found ID
ID 1:
ID 2:
I used Anthony's solution below for the most part. I did change the template match to just use Attr and then used a choose stement to filter on my Names. In most cases I just need the Value. In other case I needed to customize, thisreally cut down on the number of templates I needed. (Thanks again for the start in the right direction to everyone who helped)
<xsl:template match="Attr">
<xsl:choose>
<xsl:when test="@N='IsValid'">
<xsl:value-of select="@V" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@V" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>