SolutionCottage.com
Posted  05 Nov 2008 - 13:04:29

Category: XML


select distinct value of attribute in XML using XSLT

Issue: Say you have this XML:

<errors>
<error id="1">Invalid E-mail</error>
<error id="2">Invalid Username</error>
</errors>


You might want to select the data at error with id number 2.

Solution:
A good idea is to check if the tag error with number 2 exists, and in that case show the message that is associated with it. Here is the code:

<xsl:if test="//@id='48'">
<div class="form_error">
<xsl:value-of disable-output-escaping="yes" select="//error[@id='48']" />
</div>
</xsl:if>

You could use more specified xpaths for this as well, instead of searching through the whole XML.








0 comments:








© SolutionCottage 2008-2011 9/24/2017 1:14:35 PM