Re: [xsl] Checking for existence of a string within node-set

Subject: Re: [xsl] Checking for existence of a string within node-set
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 26 Apr 2002 00:05:31 +0200
Hi Manny,

Is it something like the following?

<xsl:variable name="xml2" select="document('xml2.xml')/MMM/NNN/OOO"/>

<xsl:template match="AAA">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="BBB">
  <xsl:if test="$xml2[@name = current()/@name and
                        (@mode = 1 or @mode = 2)]">
    <xsl:copy>
      <xsl:copy-of select="CCC"/>
      <DDD>...</DDD>
      <EEE>...</EEE>
    </xsl:copy>
  </xsl:if>
</xsl:template>

Regards,

Joerg

Manny Parasirakis wrote:
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






XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread