This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Checking for existence of a string within node-set
- From: Manny Parasirakis <mannyp at atg dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 25 Apr 2002 17:41:58 -0400
- Subject: [xsl] Checking for existence of a string within node-set
- Reply-to: xsl-list at lists dot mulberrytech dot com
Does anyone know of any way to check for the existence of a string within
an attribute inside a node within a node-set? I am trying to transform an
XML file by only selecting the tags whose name attribute matches the name
attribute in another xml file's tag. Example:
xml1.xml
<AAA>
<BBB name="xxx">
<CCC>...</CCC>
</BBB>
<BBB name="yyy">
<CCC>...</CCC>
</BBB>
<BBB name="zzz">
<CCC>...</CCC>
</BBB>
</AAA>
xml2.xml
<MMM>
<NNN>
<OOO name="xxx" mode="1"/>
<OOO name="yyy" mode="2"/>
<OOO name="zzz" mode="3"/>
</NNN>
</MMM>
I am transforming xml1.xml using information within the attributes in
xml2.xml. I would like the output to look like this:
<AAA>
<BBB name="yyy">
<CCC>...</CCC>
<DDD>...</DDD> <--- This would be added by the transform
<EEE>...</EEE> <--- This would be added by the transform
</BBB>
<BBB name="zzz">
<CCC>...</CCC>
<DDD>...</DDD> <--- This would be added by the transform
<EEE>...</EEE> <--- This would be added by the transform
</BBB>
</AAA>
Basically what is happening is that the BBB tag would only be included if
its name attribute exists in xml2.xml within the OOO name attribute and the
mode attribute is 1 or 2. In addition, during the transform I would like to
add the DDD and EEE tags within each BBB tag.
I tried using xsl:foreach within another xsl:foreach to iterate through
each name attribute within xml2.xml and then using an xsl:if to check if
the strings match. Within the if I use an xsl:copy which adds the DDD and
EEE tag but then closes the BBB tag and writes the CCC tag outside of the BBB.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list