You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by xmlizer <mo...@netcourrier.com> on 2004/11/08 12:35:38 UTC

How to surround an element with efficacity ?

Hello

As I am writing XSLT documents, i was in a some case in this situation :

In one case, i want to surround an element with another one, in another 
case i don't

example :

if (@LINKED=='true') {
	<a href="....">
		content
	</a>
} else {
	content
}

I name this case "conditional surrounding"

where content is a multiline stuff

of course i see some of those saying i just have to call a template, but 
  the content stuff use a lot of parameters so it is the same to 
copy/paste than to make a call.

So my questions are those

1) Can be handled simply in strict XSLT 1.0 ?
2) Can be handled simply with some extension of XSLT 1.0 ?
3) Can it be handled simply with last XSLT 2.0 WD ?
4) with XQuery ?
5) should I use XSP ?
6) Should I use direct programming langages ?
7) Should I change the structure of the XML input and how ?

etc.

Of course there is a awful way to do that with

and $name could be "a" or "span" for exemple

<xsl:variable name="name">
   <xsl:choose>
     <xsl:when test="@LINKED=='true'">a</xsl:when>
     <xsl:otherwise>span</xsl:otherwise>
   </xsl:choose>
</xsl:variable>

<xsl:element name="{$name}">
   <xsl:if test="$name == a">
     <xsl:attribute name="href" select="$href" />
   </xsl:if>
    content
</xsl:element>

Cheers

Xmlizer


---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: How to surround an element with efficacity ?

Posted by Torsten Curdt <tc...@apache.org>.
xmlizer wrote:
> Hello
> 
> As I am writing XSLT documents, i was in a some case in this situation :
> 
> In one case, i want to surround an element with another one, in another 
> case i don't
> 
> example :
> 
> if (@LINKED=='true') {
>     <a href="....">
>         content
>     </a>
> } else {
>     content
> }

What about

<xsl:template match="whatever[@LINKED='true']">
   <a href="...">
     content
   </a>
</xsl:template>

<xsl:template match="whatever">
   content
</xsl:template>

cheers
--
Torsten

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org