[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Selecting and printing certain nodes

Subject: RE: Selecting and printing certain nodes
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Fri, 20 Feb 2004 00:50:45 +0100
printing xsl param
> -----Original Message-----
> From: Glenn MacGregor
>
<snip />
> Although my input no longer looks like:
>

Hmm. I'll start by giving 'a' solution for the original layout, then see if
we can adapt it to use the adapted one

<xsl:stylesheet ...>
...
<xsl:template match="/">
  <xsl:apply-templates select="foreach/item" />
</xsl:template>

<xsl:template match="item">
  <xsl:apply-templates select="../do">
    <xsl:with-param name="pitem" select="." />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="do">
  <xsl:param name="pitem" />
  <xsl:apply-templates>
    <xsl:with-param name="pitem" select="$pitem" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="node()">
  <xsl:param name="pitem" />
  <xsl:copy>
    <xsl:apply-templates>
      <xsl:with-param name="pitem" select="$pitem" />
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="var">
  <xsl:param name="pitem" />
  <xsl:value-of select="$pitem" />
</xsl:template>
</xsl:stylesheet>

Actually, I think it would be even simpler to say:

<xsl:stylesheet ...>
...
<xsl:template match="/">
  <xsl:apply-templates select="foreach/do" />
</xsl:template>

<xsl:template match="do">
  <xsl:variable name="vdo" select="*"/>
  <xsl:for-each select="../item">
    <xsl:apply-templates select="$vdo">
      <xsl:with-param name="pitem" select="." />
    </xsl:apply-templates>
  </xsl:for-each>
</xsl:template>

<xsl:template match="node()">
  <xsl:param name="pitem" />
  <xsl:copy>
    <xsl:apply-templates>
      <xsl:with-param name="pitem" select="$pitem" />
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="var">
  <xsl:param name="pitem" />
  <xsl:value-of select="$pitem" />
</xsl:template>

</xsl:stylesheet>

>
> It looks like:
>
> <foreach param="devices">
> <tr><td><b>BOLDFACE</b> Some Text</td><td>Here</td></tr>
> <tr><td> Test11</td><td>Test</td></tr>
> </foreach>
>
> Along with this fragment of XML I also have another XML file name
> @param.xml
> (devices.xml) which contains an XML list of all the devices I want to loop
> through
> <doc>
> <item>dev1</item>
> <item>dev2</item>
> <item>dev3</item>
> <item>dev4</item>
> </doc>
>

So, change the template to something like:

<xsl:stylesheet ..>
..
<xsl:template match="/">
  <xsl:apply-templates select="foreach/do" />
</xsl:template>

<xsl:template match="do">
  <xsl:variable name="vdo" select="*" />
  <xsl:for-each select="document(
      concat($some_directory,.,'.xml')
         )//doc/item">
    <xsl:apply-templates select="$vdo">
      <xsl:with-param name="pitem" select="." />
    </xsl:apply-templates>
</xsl:template>

<!-- copy the node() and var templates from above -->

</xsl:stylesheet>


Hope this helps!

Cheers,

Andreas


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.