This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: document function and counting


Two suggestions:

First, what you might call 'two passes within one stylesheet'.
Put the result of processing the two external documents into a
variable, and then do an apply-templates on that.  xsl:number will now
be able to see the whole 'tree'.
Cons:
  *  you have to use the node-set extension function (not as big a
portability problem as other extensions, as most processors support it
in some form or another, and you should be able to do the same thing
as standard in the next version of XSLT)
 *  you will have made a copy of all the nodes in the external
document,  so you are putting a lower limit on the size of document
you can handle

Second, a way round your difficulty with parameters.
You can do something like (not tested / checked):
     <xsl:variable
         name="count1"
         select="count(document('foo1.xml')/item)"
     </xsl:variable>
     <xsl:apply-templates select="document('foo1.xml')/item">
          <xsl:with-param name="start" select="1"/>
     </xsl:apply-templates>
     <xsl:apply-templates select="document('foo2.xml')/item">
          <xsl:with-param name="start" select="$count1"/>
     </xsl:apply-templates>

Your item number is based on $start+position()

This *looks* like you are reading foo1.xml twice.  But an XSLT
procesor is required to return the *same* document (i.e. exactly the
same root node) given identical URIs.  So, don't worry too much about
the apparent performance problem - there isn't one.

Cons:
  won't work if you need to use xsl:number for some complicated
scheme.

It should be possible to get both methods to work given an arbitrary
number of subsidiary documents.

Regards,
Trevor Nash
>
>
>I am trying to use the document function to pull in the result trees of
>other documents and then I want to number things across the entire new
>document in one pass.
>
>For example say I have a file called master.xml which contains uri's to
>other documents called foo1.xml and foo2.xml.  Say foo1.xml and foo2.xml
>each contain a list of <item> tags.
>
>I want the output of the transformation to be a document which contains
>all of the <item>s of both foo1.xml and foo2.xml AND I want to number them
>continuously from the top to the bottom.  I want to do this in one pass of
>a stylesheet.
>
>I can pull foo1.xml and foo2.xml into the output file using document().
>Also, if all of the items are already in the same document I can easily
>number them using the <xsl:number> tag.  However, it is not possible to do
>both in the same run of the stylesheet because xsl:number does not seem to
>have access to the elements in main.xml and either foo1.xml or foo2.xml at
>the same time. So I can reach my goal if I write two stylesheets and run
>them one after each other, but I don't want to do that.
>
>Alternatively, I have tried using parameters to pass a number into the
>item template.  However, I don't know how to get this information from the
>point where the template matches an <item> in foo1.xml to a point where it
>matches <item> in foo2.xml.  That is, I cannot pass parameters up the
>tree.
>
>Could someone please explain how I should do this?  Or, is it even
>possible?
>
>Thank you so much for your time.
>
>Sarah Coppin
>
>
>
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@melvaig.co.uk

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]