Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Variables in XSLT [Thread Next] Re: Variables in XSLTTo: 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 | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
