Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Can you pass a parameter from a stylesheet to the resulting HTML file?

From: Kathryn.Grant@-----------------
To:
Date: 6/4/2002 9:30:00 AM
Joerg,

Once again, I really appreciate your help.  The problem isn't solved yet,
but I think it's because I oversimplified my original explanation and code.

Here's a better simplified version of my xhmtl file:

<table>
   <tr>
 	<td>
 	   <ol>
 		<li>item 1</li>
 		<li class="mgronly">item 2</li>
 		<li>item 3</li>
 	   </ol>
 	</td>
   </tr>
 
   <tr>
 	<td>
 	   <ol start="var">
 		<li>item 4</li>
 		<li>item 5</li>
 		<li>item 6</li>
 	   </ol>
 	</td>
   </tr>
</table>

I am transforming this document into two different documents by using two
different xsl files.  The first xsl file simply copies everything:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    version="1.0">

<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="node() | @*">
		<xsl:copy>
			<xsl:apply-templates select="node() | @*"/>
		</xsl:copy>
	</xsl:template>

</xsl:stylesheet>


The second xsl file filters out any <li> item with a class of "mgronly":

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    version="1.0">

<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="node() | @*">
		<xsl:copy>
			<xsl:apply-templates select="node() | @*"/>
		</xsl:copy>
	</xsl:template>

<xsl:template match="xhtml:li[@class='mgronly']"/>

</xsl:stylesheet>

Here's what I'm trying to do:  In the first transformation, I need to
replace "var" in the second <ol> tag with "4".
In the second transformation, because one of the preceding <li> items is
filtered out, I need to replace "var" with "3".  (I don't need to have the
XSL files count the <li> items to compute the "4" and "3", unless it's very
easy.  I can just hard code "4" and "3".) Is there a way to do this?

Thanks again for all your help--

Kathryn

Date: Sat, 01 Jun 2002 01:34:52 +0200
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Subject: Re: [xsl] Can you pass a parameter from a stylesheet to the
resulting HTML 	file?

Hello Kathryn,

it's a bit difficult to see, what you are doing with your two 
stylesheets. In general you can do it in the following:

<xsl:template match="foo">
   <xsl:apply-templates select="bar">
     <xsl:with-param name="name-of-param" select="value-of-param"/>
   </xsl:apply-templates>
</xsl:template>

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

If your stylesheet below runs on the XML below, you can do something 
like the following:

<xsl:template match="node() | @*">
   <xsl:copy>
     <xsl:apply-templates select="node() | @*"/>
   </xsl:copy>
</xsl:template>

<xsl:template match="ol">
   <ol start="{count(preceding::ol) + 1}">
     <xsl:apply-templates select="node() | @*"/>
   </ol>
</xsl:template>

Regards,

Joerg

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


transparent
Print
Mail
Digg
delicious
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