Using
/*/DiagList /* [@icd = /*/ICDList/* [contains(@description, $pText)] /@id ]
where $pText should be replaced with the required string literal.
XSLT Based Validation :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:my "> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:param name="pText" select="'ir'"/> <xsl:template match="/"> <xsl:copy-of select= "/*/DiagList /* [@icd = /*/ICDList/* [contains(@description, $pText)] /@id ]"/> </xsl:template> </xsl:stylesheet>
when this conversion is applied to the provided XML document (corrected for the correct form):
<t> <DiagList> <Diag id="1" icd="400"/> <Diag id="2" icd="401"/> <Diag id="3" icd="402"/> <Diag id="4" icd="400"/> </DiagList> <ICDList> <ICD id="400" description="First one"/> <ICD id="401" description="Second one"/> <icd id="402" description="Third one"/> </ICDList> </t>
selected nodes are selected and copied to the output :
<Diag id="1" icd="400" /> <Diag id="3" icd="402" /> <Diag id="4" icd="400" />
when we set in the above conversion :
<xsl:param name="pText" select="'st'"/>
, then again the desired result is obtained:
<Diag id="1" icd="400" /> <Diag id="4" icd="400" />
source share