Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL IF

Status
Not open for further replies.

acsooley

Programmer
Nov 13, 2002
32
0
0
CA
Can I use a xsl if before the xsl:template?

Such as

<xsl:param name="$test"/>
<xsl:if test="$test = "new">
<xsl:include href="NEW-URL/text.xsl"/>
</xsl:if>
<xsl:if test="$test = "old">
<xsl:include href="OLD-URL/text.xsl"/>
</xsl:if>

<xsl:template match="/">

Other XSL code

</xsl:template>


Thanks
Adam
 
You have to be inside a template to access the DOM structure of the XML...

The only thing placing variables outside the template is good for is to define constants (values that do not change)
Say you will be using PI, you could define it at the top as:
<xml:variable name="pi" select="3.14159265" />

in which case, you could then use $pi instead of typing out 3.14159265 every time in the rest of the XSL...

plus, if you made a typo, you fix it in one place, instead of having to change every instance...

It would be useless to use <xsl:if> outside the template, due to the fact that since you would be dealing with constants, the results would always be the same, which would in turn eliminate the need for them.

On the other hand, you can make multiple templates, so you could use one for your <xsl:if> statements, then branch off to different areas from there...

In other words, include the XSL code, from the 2 files you refer to, as Named templates, then use <xsl:if> to call them...

Here is some more info on this:


Hope this helps,
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Yes but the $test pram can change. It is passed through the jsp depending what server the page is loaded from.

 
hmmmm...
Read this:

BUT...
if you are using some language (JSP) to transform the XML via the XSL, you sould be able to use DOM (or something) to modify the XSL before transforming the XML...

Just load the XSL into a DOM, then use java to select the conditions, then use appendChild to add whatever <xsl:include href="x" /> element you want to use...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top