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

RE: generate-d( ) not working

Subject: RE: generate-d( ) not working
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Tue, 1 Jul 2003 21:12:00 -0500
d not date
> I am confused as to what your questions is. As far as what i 
> am trying to do
> is that i want the target of the linked items to be at the 
> very bottom of my
> output HTML. Right not it is putting them at the top. The 
> links seem to be
> working fine for me.

John, I think there needs to be some basic understanding of how
template matching works.
You appear to be trying to control what nodes a template will
match by giving the template a certain name.  A template's name
doesn't have any effect unless you use xsl:call-templates, which
you're not.


Walking through your stylesheet from the top,
first, there is no template that matches "/" (the root node),
so the default template is applied, which applies-templates
to the root node's children, i.e. the document node, which is
HSContract.

There are three templates that match "HSContract".  One is the first
template, which has match="HSContract". Then there are two templates
with exactly the same match pattern, match="*" (and the same priority,
since you didn't give a priority.) This is an error, though your XSLT
processor may just pick one (as it apparently did) instead of giving
an error message.
Anyway, in this case the template with match="HSContract" has a higher
default priority so it gets invoked.

This first template in your stylesheet outputs <html>, <head>,
<body>; and inside <body> it applies-templates to "*", that is,
all children.

The first child of HSContract is imagePath, so the stylesheet
processor looks for a template that matches imagePath elements.
The only two templates that match it are the ones with match="*".
So your XSLT processor picked the last one, which is named "HSLinker".
This template is invoked, and
it generates targets for all your links. Then it moves on
to apply templates to HSDataContainerType and HSDocumentation.
There's your problem.

You want your targets to appear at the bottom of the page.
To change the order in which templates are applied,
apply them separately to the different children, so
you can specify the order.

So in the first template, instead of
		<xsl:apply-templates select="*"/>
you can say
		<xsl:apply-templates select="HSDataContainerType" />
		<xsl:apply-templates select="HSDocumentation" />
		<xsl:apply-templates select="imagePath" />
which is equivalent to what you were doing, but in a different order.
That should give you what you want.


However, this is pretty bad style because you're using imagePath
as a dummy to apply a template that has nothing to do with imagePath.
So I would change that to
		<xsl:apply-templates select="HSDataContainerType" />
		<xsl:apply-templates select="HSDocumentation" />
		<xsl:apply-templates select="//HSString" mode="target" />

and change your HSLinker template to:

	<xsl:template name="HSLinker" match="HSString" mode="target">
		<b>Input Description:</b><br /><br/>
		<a name="{generate-id(.)}">
		Name:<xsl:value-of select="@name" /><br />
		Required: <xsl:value-of select="@required" /></a><br /><br />
     </xsl:template>

(I assume you're using names like "HSLinker" as sort of comments.
Template names don't actually affect anything unless you use
xsl:call-template.)

But that will cause conflicts in some cases with your template named
"HSLink", so change that one to:

	<xsl:template name="HSLink" match="HSString" mode="link">
	...
	</xsl:template>

and call it using apply-templates with mode="link".

> 
> <xsl:template name="HSLink" match="//HSString">
> 	<img src="texticon.gif"><a href="#{generate-id(.)}">
> 	<xsl:value-of select="@name" /></a><br /></img>
>   </xsl:template>
> 
>  <xsl:template name="HSLinker" match="*"><b>Input 
> Description:</b><br /><br
> />
>     <xsl:for-each select="//HSString">
> 		<a name="{generate-id(.)}">
> 		Name: <xsl:value-of select="@name" /><br />
> 		<xsl:if test="@required!=''">
> 			Required: <xsl:value-of select="@required" />
> 		</xsl:if></a><br /><br />
>     </xsl:for-each>
>   </xsl:template>
> 
> How do you make some section of your XSLT be processed in the 
> end? I think
> the match = "*" of the 'HSLinker' template is messing up. It 
> is making that
> XSLT code to be processed first somehow.

Yep, you were right.

> Do you know how the ordering works for the templates i.e 
> which template gets
> processed first when the output HTML is being generated?

I would suggest Jeni Tennison's "Beginning XSLT" book or Michael Kay's
reference.
Both explain how the processing model of XSLT works.
Without learning this at a basic level, you're going to have a
really hard time getting stylesheets to work.

Lars


 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.