xsl-list
[Top] [All Lists]

Re: iterating a nodeset (provided by XML or XSL) in a custom template (image-chooser)

2003-04-09 03:12:50

I am looking for a template that iterates over a given set (of nodes
describing images) and picks a right one based on criteria (e.g. img 
width<display
width.... ;-) )

Depending on exactly what the test is, you don't need a template for
that, just an Xpath predicate, eg if $set is a set of <img/> nodes

$set[(_at_)width &lt; $displaywidth]

is the subset of that set with width attribute less than the
$displaywidth variable.

but with that code, the instructions from <xsl:template name="header-image">
were simply copied, not applied.
No the instructions in teh template will have been applied, but without
seeing the template it's hard to say why you did not get what you
expected.


  - in general, how can I _build_ a nodeset in an XSL template and pass it as
  a parameter xsl:call-template? (and what's the best way to process that
  nodeset?)

If you are actually constructing nodes then you can not do this in XSLT
1 without a node-set extension function to convert the result tree
fragment back to a node set, but I do not think you are doing that here,
you are not building new nodes, just getting them from the source or the
stylesheet. Actually it's probably a bit easier to have your other image
documents not directly in your xsl file but in a sibling xml file that
you bring in via document() 

I'm not sure how work through a list of images.

if you have some <img/> elements  in the main source file and some in a file say
defautimage.xml then you can just

<xsl:apply-templates 
  select="/some/path/to/img | 
document('defautimage.xml')/some/other/path/to/img"/>

will apply templates to images in your input document and your
defautimage.xml file.
However you have to decide what the Xpaths need to be based on teh
structure of your input.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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



<Prev in Thread] Current Thread [Next in Thread>