Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Tracking "already-processed" elements

From: "David Carnes" <davidc@----------------.--->
To: NULL
Date: 6/3/2004 10:49:00 AM
Cary:
I think <xsl:template> and <xsl:apply-templates> will work for you.

Given this XML:
<data>
  <thing name="a"/>
  <thing name="d"/>
  <thing name="a"/>
</data>

...and this XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method='text' indent='yes' omit-xml-declaration='yes' />
  <xsl:template name="data" match="data">
    <xsl:apply-templates select="thing[@name='a']"/>
    <xsl:apply-templates select="thing[@name!='a']"/>
  </xsl:template>

  <xsl:template match="thing[@name='a']">
    thing 1
  </xsl:template>

  <xsl:template match="thing[@name!='a']">
    thing 2
  </xsl:template>
  </xsl:stylesheet>

...will yield:

    thing 1

    thing 1

    thing 2

I leave the implementation up to you.  Have fun!
Oh, BTW, download Xselerator; it's a great tool.
http://www.marrowsoft.com/

Ciao,
Dave


"Cary Millsap" <cary.millsap@h...> wrote in message
news:10bs84hh6vspd63@c......
> I have a list L that contains values that are @name attribute values in
> elements of the input document. In my application, I need to traverse L,
> processing input document elements whose @name attribute values match
items
> from L. However, L doesn't contain all the names in the input document.
> Therefore, when I'm finished traversing L, I need to walk the input
document
> to process all the elements that weren't processed during the traversal of
> L. (There's a simplified example below my signature.)
>
> I can think of two ways to approach this problem, but I'm not sure which
is
> a more elegant XSL answer (or even if a way I'm not considering would be a
> smarter way to go):
>
> a) Attach an @has-been-processed attribute to the input document elements
as
> they're processed during the pass through L. (Is it even possible to do
this
> in XSL?)
>
> b) Whenever I process a set of elements in the input document, append
those
> elements' @id values in a separate data structure and then (somehow that I
> have yet to figure out) add a predicate that says "...and the element's
@id
> value is not in the already-processed list."
>
> Thank you very much for your advice.
>
>
> Cary Millsap
>
>
> Simplified example:
>
> - L contains the names "a" and "b".
> - Input document contains the following elements:
>     <thing name="a" .../>
>     <thing name="d" .../>
>     <thing name="a" .../>
>
> Step 1: For each element in L, process the input document's elements with
> that name. This pass will pick up the two 'a' elements. (I have figured
out
> already how to avoid emitting anything for 'b', since it is not
represented
> in the input document.)
> Step 2: For the input document elements that are left over, process those
> elements. This pass will pick up the 'd' element that was not addressed in
> Step 1.
>
>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent