xsl-list
[Top] [All Lists]

Re: xsl:for-each...iteration question

2005-04-19 10:12:37
Hi Paul,
  Please also try this XSL.. You may like it..

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  
<xsl:output method="xml" indent="yes" />
  
<xsl:variable name="exclude"
select="document('exclude.xml')" />
  
<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>
  
<xsl:template match="*[(_at_)attr-name =
$exclude/exclude-list/exclude-attr]" />
  
</xsl:stylesheet>

This is a modified identity stylesheet.. The 2nd
template excludes those elements, whose attr-name
attribute has value matching that in exclude file..

I have found.. identity template is a really powerful
piece of code which lets us do complex things..

Regards,
Mukul

--- Paul Coletti <pcoletti(_at_)novell(_dot_)com> wrote:
This has been answered before I'm sure but doing a
relevant search in the archives is tricky.
 
I've an input doc containing a number of modify-attr
elements
<modify>
  <modify-attr attr-name = "abc"/> 
  <modify-attr attr-name = "123"/>
  <modify-attr attr-name = "789"/>
</modify>
 
I have another document containing a list of
prohibited attributes.
<exclude-list>
  <exclude-attr>123</exclude-attr>
</exclude-list>
 
 
I want to iterate over my input doc and copy all
those modify-attr elements that are NOT in the
exclude list to the output.
 
<xsl:template match="modify/modify-attr">
  <xsl:variable name="currentAttr"
select="@attr-name"/>
  <xsl:variable name="currentNode" select="."/>
 
  <xsl:for-each

select="document('excludedoc')/exclude-list/exclude-attr">
    <xsl:when test="$currentAttr=.">
      <xsl:message>Exclude</xsl:message>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="$currentNode"/>
    </xsl:otherwise>
  </xsl:for-each>
 
</xsl:template>
 
Obvisouly, this is flawed, I get multiple
modify-attr elements copied to the output because I
cannot see a way of ensuring the for-each only
copies a permitted node once and once only.
 
I've a feeling this is approaching the problem from
the wrong way....
 
 
 



--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




                
__________________________________ 
Do you Yahoo!? 
Plan great trips with Yahoo! Travel: Now over 17,000 guides!
http://travel.yahoo.com/p-travelguide

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--