|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Comparing 2 different elements
I need to check to see if attribute from element 1 equals an attribute from element 2.
Logically this is not easy. Can any offer any help? <xml> <element1 id="1" /> <element1 id="2" /> <element2 id="1" /> <element2 id="2" /> </xml> <xsl:for-each select="element1"> <xsl:if test="//xml/element2/@id = @id> Do soemthing </xsl:if> </xsl:for-each> |
|
#2
|
|||
|
|||
|
You need to do something like the following using a "compare attribute named template:
Code:
<?xml version="1.0"?> <elements> <element1 id="1"/> <element1 id="2"/> <element2 id="1"/> <element2 id="2"/> </elements> Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="elements">
<xsl:text>Match = </xsl:text>
<xsl:call-template name="compareAttribute">
<xsl:with-param name="parm1" select="element1/@id"/>
<xsl:with-param name="parm2" select="element2/@id"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="compareAttribute">
<xsl:param name="parm1" select="."/>
<xsl:param name="parm2" select="."/>
<xsl:choose>
<xsl:when test="$parm1 = $parm2">Yes</xsl:when>
<xsl:otherwise>No</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Comparing 2 different elements |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|