Hi Jim,
At 12:19 PM 3/15/2004, you wrote:
I've trying to work on this XSL transformation but I am running into a wall.
Can some help me get started?
Well since you're not telling us exactly where you're stumped, I'll try to
provide some hints regarding what you ask about -- getting started.
The interesting thing about this stylesheet, first off, is that unlike the
"normal" case, the structure of your output has no relation to the
structure of your input. Your input rows are in alphabetical order, it is
true, but in your output you want to list the entire alphabet, which has no
representation as such in the source document.
This suggests that your stylesheet should work by iterating over the
letters of the alphabet. Every time it gets a letter, it will then retrieve
those rows from the source that belong with that letter. (This is what we
call a "pull" in the business, as opposed to a "push", which refers back to
the source document to figure out what to do next.)
There are many ways to iterate over the letters of the alphabet, given that
the alphabet itself isn't available (as an ordered list) in your source
document. Two in particular come to mind, either of which would work fine.
First, you can define a string variable to include the alphabet,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", and then use a recursive template to chop the
string down one letter at a time, calling itself with the remainder, until
there are no letters left. Each invocation of the template with a new
letter would then pull the data from the source document that you goes with
that letter.
Or you could define a "lookup table" node set in your stylesheet, along the
lines of
<u:lookup xmlns:u="yourURL/XSLT/util">
<letter>A</letter>
<letter>B</letter>
...
<letter>Z</letter>
</u:lookup>
... and then process this node set using the document() function to query
into the stylesheet (where the node set is). Again, as you pick up each
letter you will then go grab the data that belongs with it in the source.
This option is perhaps a little less obscure than the other, or more
obscure, depending on what you consider obscurity to be.
You can find information on both recursion ("Recursion Examples") and
lookup tables ("Lookup") in the XSL FAQ at
http://www.dpawson.co.uk/xsl/sect2/sect21.html, to help you move along with
this.
Write again if you get stuck or if these hints are insufficient or don't
address your actual problem.
Cheers,
Wendell
I need an xsl to conver this xml:
<XML>
<row Key_ID="2" Keyword="A-10" Description="A-10 Warthog ARF w/
Ducted Fans" Status="active"/>
<row Key_ID="3" Keyword="Aerobird Challenger"
Description="Aerobird Challenger RTF " Status="active"/>
<row Key_ID="5" Keyword="CARISMA" Description="CARISMA R/C CARS"
Status="active"/>
<row Key_ID="4" Keyword="Mech Warrior" Description="Mech Warrior:
Fire For Effect Booster Pack " Status="active"/>
<row Key_ID="1" Keyword="Mini-T" Description="Mini-T RTR
1/18-Scale Off-Road Truck" Status="active"/>
</XML>
To:
<?xml version="1.0" encoding="UTF-8"?>
<Keywords xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Keyword Letter="A">
<Term>
<Id>2</Id>
<Name>A-10</Name>
<Definition>A-10 Warthog ARF w/ Ducted
Fans.</Definition>
<status>active</status>
</Term>
<Term>
<Id>3</Id>
<Name>Aerobird Challenger</Name>
<Definition>Aerobird Challenger RTF..</Definition>
<status>active</status>
</Term>
</Keyword>
<Keyword Letter="B">
</Keyword>
<Keyword Letter="C">
<Term>
<Id>5</Id>
<Name>CARISMA</Name>
<Definition>CARISMA R/C CARS</Definition>
<status>active</status>
</Term>
</Keyword>
<Keyword Letter="D"/>
<Keyword Letter="E"/>
<Keyword Letter="F"/>
<Keyword Letter="G"/>
<Keyword Letter="H"/>
<Keyword Letter="I"/>
<Keyword Letter="J"/>
<Keyword Letter="K"/>
<Keyword Letter="L"/>
<Keyword Letter="M">
<Term>
<Id>4</Id>
<Name>Mech Warrior</Name>
<Definition>Mech Warrior: Fire For Effect Booster
Pack</Definition>
<status>active</status>
</Term>
<Term>
<Id>1</Id>
<Name>Mini-T</Name>
<Definition>Mini-T RTR 1/18-Scale Off-Road
Truck</Definition>
<status>active</status>
</Term>
</Keyword>
<Keyword Letter="N"/>
<Keyword Letter="O"/>
<Keyword Letter="P"/>
<Keyword Letter="Q"/>
<Keyword Letter="R"/>
<Keyword Letter="S"/>
<Keyword Letter="T"/>
<Keyword Letter="U"/>
<Keyword Letter="V"/>
<Keyword Letter="W"/>
<Keyword Letter="X"/>
<Keyword Letter="Y"/>
<Keyword Letter="Z"/>
</Keywords>
Jim
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list