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

Re: a simpler version ???

Subject: Re: a simpler version ???
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Jul 2000 11:38:29 +0100
xsl cycle through details
Jean-Claude,

>I wrote these documents (dtd, xml and xsl) and it runs. But I think that my
>stylesheet is too complex.

Having had a quick look through, the only areas that might be simplified
that I can see are:

In this template:

<xsl:template match="Components_Elements" mode="table-of-contents">
  <div id="contents">
    <xsl:for-each select="Component/Component_Core">
      <xsl:sort select="@Name" order="ascending" />
         <br><a href =
"#{generate-id(key('Component-Component_core_name',@Name))}"><xsl:value-of
select="@Name" /></a></br>
    </xsl:for-each>
  </div>
</xsl:template>

Within the xsl:for-each, your current node is a Component_Core.  When you
do key('Component-Component_core_name', @Name), you are accessing the
Component with a Component_Core sub-element with the same value for the
@Name attribute as the current Component_Core element.  Assuming that the
Component/Component_Core/@Names are unique, this is exactly the same as
getting the parent (Component) element of the current Component_Core.  So,
you could simplify this to:

<xsl:template match="Components_Elements" mode="table-of-contents">
  <div id="contents">
    <xsl:for-each select="Component/Component_Core">
      <xsl:sort select="@Name" order="ascending" />
      <br><a href="#{generate-id(..)}"><xsl:value-of select="@Name"
/></a></br>
    </xsl:for-each>
  </div>
</xsl:template>

Within your Components_Elements-matching (details mode) template, you have:

<xsl:for-each select="Component">
  <xsl:variable name="ComponentName" select="Component_Core/@Name"/>
  <xsl:sort select="Component_Core/@Name"/>
  ...
</xsl:for-each>

The xsl:sort element must be the first child of the xsl:for-each element
[http://www.w3.org/TR/xslt#sorting] (although SAXON at least doesn't seem
to complain - maybe it just ignores it).

Within the same template, you later cycle through each of the Expansions
for the particular Component.  This is where most of the complexity that
you were worried about lies:

<xsl:for-each
select="Element[key('Component-Component_context_id',@id)/Component_Core/@Na
me]">

Here you are selecting the Element elements that you want to cycle through.
 I don't exactly understand what you are trying to achieve with the
predicate (the bit in []s).  It will be selecting only Elements that have
associated Components that have Component_Core children than have @Name
attributes.  You could probably simplify it quite a bit by assuming that
you're using a validating processor.  If you are using a validating
processor, then

(a) all Component elements have Component_Core children
(b) all Component_Core elements have @Name attributes

So you can probably get away with:

<xsl:for-each select="Element[key('Component-Component_context_id', @id)]">

This will make sure that you only select Elements that have the same @id
attribute as an existing Component_Context - if you're using a validating
processor, the only other option would be that they would refer to a Link
element.  It might be that you can simplify your stylesheet even more if
you can guarantee that won't happen through using a schema.

The next is:

<xsl:sort
select="key('Component-Component_context_id',@id)/Component_Core/@Name"/>

I can't see any way of simplifying that.

Then you have two lines that refer to the Component that is associated to
the Element through the @id attribute:

<a href="#{generate-id(key('Component-Component_context_id',@id))}">
  <xsl:value-of
select="key('Component-Component_context_id',@id)/Component_Core/@Name" />
</a>

You could simplify that by defining a variable to hold the Component that
you're referencing:

<xsl:variable name="child"
              select="key('Component-Component_context_id', @id)" />
<a href="#{generate-id($child)}">
  <xsl:value-of select="$child/Component_Core/@Name" />
</a>

though you might just say that adds another line to your stylesheet! ;)

So, sorry that I can't be of more help to you, but what you're trying to do
is pretty complex, as is your input, so it's not that surprising that your
stylesheet is as well.

Cheers,

Jeni



 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.