Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Variables in XSLT

From: p.lepin@-------.---
To: NULL
Date: 11/3/2006 3:36:00 AM


Carles Company Soler wrote:
> Ooops. Right, I'll send everything. It's a very simple
> stylesheet to transform a custom DTD to SVG. I'll mark
> the place where the variable is used with a line of * :

Marking it with a <!-- ********* --> would've been a better
idea.

> <!-- Sujet boxes -->
> <xsl:template match="sujet">
> <rect x="{@x*$xper+10}" y="{@y*$yper+10}" height="30"
> width="150"
> style="fill:blue;stroke:black;stroke-width:2;opacity:0.5"
> />

Do you realize your code is quite unreadable? Just a bit of
indentation would help enormously.

> <!-- Arrows for each direction -->

The very idea strikes me as dubious. Determining the
direction shouldn't be all that tricky without the extra
attribute. (As long as you don't try to do anything
*seriously* tricky with your data.)

> <xsl:template match="relation">
> <xsl:variable name="aux" select="@x" />
> <xsl:variable name="auy" select="@y" />
> <rect x="{@x*$xper+10}" y="{@y*$yper+10}" ry="5"
> height="30" width="150"
> style="fill:yellow;stroke:black;stroke-width:2;opacity:0.5"
> />
>
> <text x="{@x*$xper+15}" y="{@y*$yper+28}"
> style="font-size:10px;font-weight:bold"><xsl:value-of
> select="nom" /></text>
> <xsl:choose>
> <xsl:when test="@dir='l'">
> <xsl:for-each select="id(@from)">

Note that you can replace id(@foo) with:

//*[@id]
[
  contains
  (
    concat(' ',concat(current()/@foo,' ')),
    concat(' ',concat(@id,' '))
  )
]

...AND you don't need to validate. You just need to know
what to use as an ID.

> <line x1="{@x*$xper+10}" y1="{@y*$yper+25}"
> x2="{$aux*$xper+160}" y2="{$auy*$yper+25}"
> style="stroke:rgb(99,99,99);stroke-width:2"
> marker-end="url(#Triangle)" />
> </xsl:for-each>
> <line x1="{@x*$xper+10}" y1="{@y*$yper+25}"
> x2="{id(@to)/@x*$xper+160}" y2="{id(@to)/@y*$yper+25}"
> style="stroke:rgb(99,99,99);stroke-width:2"
> marker-end="url(#Triangle)" />
> </xsl:when>

[x4]

I wonder if this rings any bells for you?

Hint #1: You wrote the code to do pretty much the same
bloody thing no less than *four* times.

Hint #2: It's a good idea to separate details of
presentation from the basic logic.

Hint #3: It's a good idea not to stuff everything into a
single template k pages long. Or, as in your case, n pages
long.

Drop the <xsl:choose>. Use <xsl:template>s with nicely
tweaked matches -- that what XPath is for. Move the gcd
into a separate named template. Consider using
attribute-sets.

-- 
Pavel Lepin



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent