sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
danmc91's Avatar

conditionalize enclosing tags with xslt


Question posted by: danmc91 (Guest) on October 20th, 2005 04:25 AM

I have a set of xml files and a .xsl file which I use to produce html
output. However, I want 2 versions of each html file. In one version,
I want the whole thing. In the second version I only want whats
inclosed by the <body> tag.

So, I tried defining a parameter which I can override on the command
line and doing something like:

<xsl:if test="$header = 'yes'">
<html>
<head>
<!--head stuff here-->
</head>
<body>
</xsl:if>

and a similar thing at the end for the closing body and html tags.
However xsltproc does not like this since I've wrapped the opening tags
and closing tags in their own if's.

Any suggestions on how to deal with this without resorting to some
awk/sed hacks?

Thanks
-Dan

2 Answers Posted
Joachim Weiß's Avatar
Guest - n/a Posts
#2: Re: conditionalize enclosing tags with xslt

danmc91 schrieb:[color=blue]
>
> <xsl:if test="$header = 'yes'">
> <html>
> <head>
> <!--head stuff here-->
> </head>
> <body>
> </xsl:if>
>
> Any suggestions on how to deal with this without resorting to some
> awk/sed hacks?[/color]

no hacks needed. Easiest solution is:
<xsl:choose>
<xsl:when test="$header = 'yes'">
<html>
<head>
<!--head stuff here-->
</head>
<body>
<!--body stuff here which is hopefully only a apply-templates or a
call-template -->
</body>
</html>
</xsl:when>
<xsl:otherwise>
<!--body stuff here which is hopefully only a apply-templates or a
call-template -->
</xsl:otherwise>
</xsl:choose>


HIH Jo[color=blue]
> Thanks
> -Dan
>[/color]
danmc91's Avatar
Guest - n/a Posts
#3: Re: conditionalize enclosing tags with xslt

Thanks! That did the trick. I'm starting to feel like if I ever get
more proficient with this stuff (DTD/XML/XSLT) it will be rather
useful!

-Dan

 
Not the answer you were looking for? Post your question . . .
196,811 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,811 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors