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

Re: Skipping surounding element

Subject: Re: Skipping surounding element
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 6 Nov 2000 18:55:21 +0000
Re: Skipping surounding element
Goetz,

> For all my 12 elements, I've a complex transformation each, that oututs
> exactly the same content for both cased, but if attr2 exists, the
> surrounding container is needed. For now I need two transformations for
> each element, is there a way to get rid of this?

There are a couple of ways to stop having to repeat code in the
stylesheet, which I think is what you're after.

One way is to store the result of transforming the content in a
variable, and then copy the content of the variable either with the
surrounding container, or without it. Thus the code for generating the
content is only involved once.  For example:

<xsl:variable name="content">
  <dest1>
    <xsl:if test="not(@attr2)">
      <xsl:copy-of select="@attr1" />
    </xsl:if>
    <xsl:apply-templates />
  </dest1>
</xsl:variable>
<xsl:choose>
  <xsl:when test="@attr2">
    <destC attr1="{@attr1}">
      <xsl:copy-of select="$content" />
    </destC>
  </xsl:when>
  <xsl:otherwise><xsl:copy-of select="$content" /></xsl:otherwise>
</xsl:choose>

The other way is to have the content be generated through the
application of a template in a particular mode:

<xsl:choose>
  <xsl:when test="@attr2">
    <destC attr1="{@attr1}">
      <xsl:apply-templates select="." mode="content" />
    </destC>
  </xsl:when>
  <xsl:otherwise>
    <xsl:apply-templates select="." mode="content" />
  </xsl:otherwise>
</xsl:choose>

...

<xsl:template match="*" mode="content">
  <dest1>
    <xsl:if test="not(@attr2)">
      <xsl:copy-of select="@attr1" />
    </xsl:if>
    <xsl:apply-templates />
  </dest1>
</xsl:template>

I hope that this helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.