|
Subject: RE: [xsl] Selecting and printing certain nodes From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx> Date: Fri, 20 Feb 2004 00:50:45 +0100 |
> -----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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Selecting and printing ce, Glenn MacGregor | Thread | Re: [xsl] Selecting and printing ce, David Carlisle |
| Re: AW: [xsl] AW: FO: ColorProof fa, Tokushige Kobayashi | Date | Re: [xsl] Arabic text rising high a, Kobayashi |
| Month |