|
-
Oct 20th, 2005, 11:04 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] XSLT v 1.0: Function
I'm new to XSLT and haven't been able to figure out a simple way to do this.
I want to create a function (subroutine, procedure, whatever you want to call it ... ) for code reusability. What's the best way to do this?
Please keep in mind that I'm using version 1 of XSLT.
Thanks!
OneSource
-
Oct 20th, 2005, 11:18 AM
#2
Re: XSLT v 1.0: Function
I think templates might be whatyour looking for.
-
Oct 20th, 2005, 11:23 AM
#3
Thread Starter
Fanatic Member
DeadEyes ...
thanks. I'm already using
VB Code:
<xsl:template match= ... >
in my stylesheet. Are you referring to something different? Could you (or anyone else) please provide a simple example of code reuse (with templates or otherwise)?
OneSource
-
Oct 20th, 2005, 02:28 PM
#4
Re: XSLT v 1.0: Function
Here is an example of using a template to create a label with a text box.
Now while the template is within the same stylesheet it could be placed anywhere and called from any other stylesheet you want.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="0">
<xsl:for-each select="gui/textbox">
<tr>
<td>
<xsl:call-template name="lbltextbox">
<xsl:with-param name="txtlabel"><xsl:value-of select="lbl"/></xsl:with-param>
<xsl:with-param name="txtcontent"><xsl:value-of select="desc"/></xsl:with-param>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<!-- this is the reusable part -->
<xsl:template name="lbltextbox">
<xsl:param name="txtlabel"/>
<xsl:param name="txtcontent"/>
<label><xsl:value-of select="$txtlabel"/></label>
<input type="text">
<xsl:attribute name="value">
<xsl:value-of select="$txtcontent"/>
</xsl:attribute>
</input>
</xsl:template>
</xsl:stylesheet>
Code:
<?xml version="1.0" encoding="windows-1250"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
<gui>
<textbox>
<lbl>item1</lbl>
<desc>1.50</desc>
</textbox>
<textbox>
<lbl>item2</lbl>
<desc>3.50</desc>
</textbox>
</gui>
-
Oct 20th, 2005, 03:37 PM
#5
Thread Starter
Fanatic Member
Thanks ....
DeadEyes ... I can now SEE the light!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|