Re: [xsl] FW: 2-step transformation

Subject: Re: [xsl] FW: 2-step transformation
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Wed, 07 Jul 2004 04:51:05 -0600
Hey Robert,

While I wouldnt recommend this particular implementation for anything larger than a "Breadcrumbs" XML source file(unless your mapping the library of congress most breadcrumb files should be somewhat manageable -- im guessing yours is as well) here's what I used on the Saxon.NET project site. Heres the link to see the actual implementation:

The genearal idea... Create an XML that maps to your site structure that starts with a "links" node as the main parent with all underlying descendants set to the name "link" and an "href" attribute set to the current directory value (I use a relative reference) and then place the reference to this file within the document function and place that into a variable called "links".

<xsl:variable name="links" select="document('links.xml')"/>

I then use a seperate "index.xml" that resides in each directory with an element that contains the value of the current directory (in the same relative format -- I usually set all of these to the root of the site by using a preceding "/" such as "/x2x2x/home" instead of "x2x2x/home" but thats up to you and beyond the scope of your question as to which is more appropriate for your situation. This index.xml contains all of the necessary content data the page for this directory correctly. It is passed to the transformation process as the main data file to be transformed. As such I can just set the following param (used to compare with the href value of each "link" element until a match is found) to the location of that element like so: (Note: This is the same general idea that you are using the id attribute for although the xml parser will notice the id attribute as a unique identifier where as my method will not... depending on your future needs or what else you may use the id attribute for you can decide which is more appropriate for your particular case)

<xsl:param name="curDir" select="/page/curDir"/>

I chose to reference the above as an xsl:param in case you decide to pass this value as a parameter via whatever implemenation you are using to transform your file. It will work either way but if you choose to implement it the way I did then I would change it to a xsl:variable instead to ensure a more consistent practice of proper use throughout your projects development.

The params from above are passed into this code block which outputs the appropriate bread crumbs and then continues the transforation of the rest of the stylesheet. As you can see, with an embedded xsl:for-each element and a reference to all descendant-or-self "link" elements using "//link" this is definitely not something you want to use with a large data source to process through :)

<xsl:for-each select="$links/links//link[@href = $curDir]/ancestor-or-self::link">
	<xsl:variable name="href">/x2x2x<xsl:for-each select="ancestor-or-self::link">/<xsl:value-of select="@href"/></xsl:for-each></xsl:variable>
	<a href="{$href}" class="locationA"><xsl:value-of select="@common"/></a> <xsl:if test="position() != last()"> &gt; </xsl:if>
	// by the way, the @common attribute value used above is the common or friendly name for the directory
	// using capitalized first letters and spaces between each word in the directory name.  Its part of each link element.

And that should do it...

Hope this helps!


 :: Got a few spare moments to write some C# code for the future of XSLT on the .NET platform? ::
  :: Visit the Saxon.NET project site found at to learn more ::

Robert Soesemann wrote:

what I am trying to do is create a breadcrumb trail based on a current
page id and a sitemap XML document. In my page.xml I have a placeholder

	<?xml-stylesheet type="text/xsl"
	<add-breadcrumb pageid="ID5"/>    <--------- final breadcrumb
HTML fragment should go here

Based on its @pageid the first XSL(generate-breadcrumb.xsl) generates
this XML fragment:

    		<item url=""area1.xml" label="area1"/>
    		<item url=""area2.xml" label="area2"/>

<item url=""areaN.xml" label="areaN"/>

   	 	<page label="thisPage"/>

To do styling and truncation task based on the page width, I need to
send this fragment through a Second XSL (style-breadcrumb.xsl) which
generates the actual HTML fragment which then be should placed in the page.xml.

How can I realise this 2-step transformation. Any ideas are welcome.

Best regards,


XSL-List info and archive:
To unsubscribe, go to:
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>

Current Thread