PDA

View Full Version : Deciphering XSL...


jgr
09-10-2005, 10:50 AM
How can I begin to learn how to break down an XSL file and understand what it's doing?

Problem: I produce a genealogy site for my family using (in part) a software program (Second Site) that takes data from my genealogy program (Master Genealogist, or TMG), massages it through XSL into HTML code.

I have access to the XSL and can change it... and want to... but haven't a CLUE what all the variables are.

In particular, here is the code for one type of output:




- <!-- Show Families with at least one child
-->
<xsl:variable name="family" select="family[count(child)>0]" />
- <xsl:if test="$family">
- <xsl:for-each select="$family">
- <!-- Show spouse/partner
-->
<xsl:variable name="children" select="child" />
- <DL>
- <DT>
<BR />
- <xsl:choose>
- <xsl:when test="count($children)=1">
<xsl:value-of select="$strchild" disable-output-escaping="yes" />
</xsl:when>
- <xsl:otherwise>
<xsl:value-of select="$strchildren" disable-output-escaping="yes" />
</xsl:otherwise>
</xsl:choose>
<xsl:text />
<xsl:apply-templates select="$prefself/name" />
- <xsl:if test="partner">
<xsl:text />
<xsl:value-of select="$strand" disable-output-escaping="yes" />
<xsl:text />
<xsl:apply-templates select="partner/pref" />
</xsl:if>
</DT>
- <DD>
- <!-- Show children
-->
- <xsl:for-each select="$children">



Using this code, I might get this output:


<DT><BR>Children of Mary Webb and <A HREF="p3.htm#i5"><SPAN CLASS=ng>David</SPAN> <SPAN CLASS=ns>Baker</SPAN></A></DT>
<DD><A HREF="p4.htm#i33"><SPAN CLASS=ng>Elizabeth</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 20 Apr 1780<BR><A HREF="p4.htm#i34"><SPAN CLASS=ng>Thomas</SPAN> <SPAN CLASS=ns>Baker</SPAN></A><b>+</b> b. 24 May 1782<BR><A HREF="p4.htm#i35"><SPAN CLASS=ng>William</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 20 Apr 1784<BR><A HREF="p5.htm#i95"><SPAN CLASS=ng>Nancy</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 31 Dec 1786, d. 15 Feb 1882<BR><A HREF="p5.htm#i36"><SPAN CLASS=ng>John Crittenden</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 27 Dec 1788<BR><A HREF="p5.htm#i37"><SPAN CLASS=ng>Mary</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 13 Oct 1792</DD>


which appears as:

Children of Mary Davenport and William Wiseman
Thomas Wiseman b. 30 Apr 1763
Dorothy Wiseman+ b. 5 Feb 1765, d. 23 Aug 1855
William Wiseman b. 5 Aug 1767
Mary Wiseman b. 11 Apr 1769
Davenport Wiseman b. 25 Aug 1771
Martin Wiseman b. 24 Aug 1773
James Wiseman b. 18 Aug 1775
John Wiseman b. 21 Feb 1777
Celestial Wiseman b. 22 Oct 1779
Susannah Wiseman+ b. 16 Dec 1781
Robert Wiseman b. 14 Jul 1784

And here is the code for another type of output for the same program:


- <!-- Show Families
-->
<xsl:variable name="family" select="family" />
- <xsl:if test="$family">
- <xsl:for-each select="$family">
- <!-- Show spouse/partner and tags
-->
<BR />
- <TABLE>
<xsl:call-template name="table-parameters" />
- <TR>
- <TD CLASS="g1">
- <B>
<xsl:value-of select="$strfamily" disable-output-escaping="yes" />
- <xsl:if test="count(../family)>1">
<xsl:text />
<xsl:value-of select="position()" />
</xsl:if>
</B>
</TD>
<TD CLASS="g2"> </TD>
- <TD CLASS="g3">
<xsl:apply-templates select="partner/pref" />
<xsl:text />
<xsl:apply-templates select="partner/lifespan" />
</TD>
</TR>
- <!-- Show children
-->
<xsl:variable name="children" select="child" />
- <xsl:if test="$children">
- <xsl:for-each select="$children">
- <TR>
- <TD CLASS="g1">
- <xsl:if test="position()=1">
- <xsl:choose>
- <xsl:when test="count($children)=1">
<xsl:value-of select="$strchild" disable-output-escaping="yes" />
</xsl:when>
- <xsl:otherwise>
<xsl:value-of select="$strchildren" disable-output-escaping="yes" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:text> </xsl:text>
</TD>
- <TD CLASS="g2">
<xsl:value-of select="position()" />
.
</TD>
- <TD CLASS="g3">
<xsl:apply-templates select="pref" />
<xsl:text />
<xsl:apply-templates select="lifespan" />
</TD>
</TR>
</xsl:for-each>
</xsl:if>
</TABLE>
</xsl:for-each>
- <!-- family loop
-->


which produces this output:


<TABLE CLASS="grid"><TR><TD CLASS="g1"><B>Spouse</B></TD>

<TD CLASS="g2"> </TD>
<TD CLASS="g3"><A HREF="p3.htm#i5"><SPAN CLASS=ng>David</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 3 June 1749, d. 15 September 1838</TD></TR>
<TR><TD CLASS="g1">Children </TD>
<TD CLASS="g2">1.</TD>
<TD CLASS="g3"><A HREF="p4.htm#i33"><SPAN CLASS=ng>Elizabeth</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 20 Apr 1780</TD>

</TR>
<TR><TD CLASS="g1"> </TD>
<TD CLASS="g2">2.</TD>
<TD CLASS="g3"><A HREF="p4.htm#i34"><SPAN CLASS=ng>Thomas</SPAN> <SPAN CLASS=ns>Baker</SPAN></A><b>+</b> b. 24 May 1782</TD>
</TR>
<TR><TD CLASS="g1"> </TD>
<TD CLASS="g2">3.</TD>

<TD CLASS="g3"><A HREF="p4.htm#i35"><SPAN CLASS=ng>William</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 20 Apr 1784</TD>
</TR>
<TR><TD CLASS="g1"> </TD>
<TD CLASS="g2">4.</TD>
<TD CLASS="g3"><A HREF="p5.htm#i95"><SPAN CLASS=ng>Nancy</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 31 Dec 1786, d. 15 Feb 1882</TD>

</TR>
<TR><TD CLASS="g1"> </TD>
<TD CLASS="g2">5.</TD>
<TD CLASS="g3"><A HREF="p5.htm#i36"><SPAN CLASS=ng>John Crittenden</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 27 Dec 1788</TD>
</TR>
<TR><TD CLASS="g1"> </TD>
<TD CLASS="g2">6.</TD>
<TD CLASS="g3"><A HREF="p5.htm#i37"><SPAN CLASS=ng>Mary</SPAN> <SPAN CLASS=ns>Baker</SPAN></A> b. 13 Oct 1792</TD>

</TR>
</TABLE>


which looks like this:

Spouse David Baker b. 3 June 1749, d. 15 September 1838
Children 1. Elizabeth Baker b. 20 Apr 1780
2. Thomas Baker+ b. 24 May 1782
3. William Baker b. 20 Apr 1784
4. Nancy Baker b. 31 Dec 1786, d. 15 Feb 1882
5. John Crittenden Baker b. 27 Dec 1788
6. Mary Baker b. 13 Oct 1792

What I would like to do is produce the following:

Children with David Baker b. 3 June 1749, d. 15 September 1838
1. Elizabeth Baker b. 20 Apr 1780
2. Thomas Baker+ b. 24 May 1782
3. William Baker b. 20 Apr 1784
4. Nancy Baker b. 31 Dec 1786, d. 15 Feb 1882
5. John Crittenden Baker b. 27 Dec 1788
6. Mary Baker b. 13 Oct 1792

What in the world am I looking for??? (And, by the way, sometimes there will be only one child and it should say Child with rather than Children with...

ktinkel
09-10-2005, 11:30 AM
How can I begin to learn how to break down an XLS file and understand what it's doing?

What in the world am I looking for??? I know from nuthin’ — but I believe this is the native format of MS Excel. Wonder what happens if you open your .xls file in Excel? (Or if you even can — might need to export in pure .xls formt.)

I hope someone who really knows will come along right about now …

jgr
09-10-2005, 11:40 AM
DUMB DUMB DUMB DUMB. I am SOOOOOO dumb. I just changed the name of this thread to "deciphering XSL" which is the web format and NOT XLS, which is the Excel format...

Sigh...

Sometimes I am just soooooooo dumb.

ktinkel
09-10-2005, 11:42 AM
DUMB DUMB DUMB DUMB. I am SOOOOOO dumb. Would you please change the name of this thread to "deciphering XSL" which is the web format and NOT XLS, which is the Excel format?Oh, of course. (And you think you’re dumb? How ’bout me, huh? <g> I mean, you had it exactly right in the body of the message.

[sigh indeed]

jgr
09-10-2005, 11:42 AM
Oh, of course. (And you think you’re dumb? How ’bout me, huh? <g>I fixed it, I think, but please double check for me. Gads, I feel soooooooooooo dumb.

Ian Petersen
09-10-2005, 08:20 PM
How can I begin to learn how to break down an XSL file and understand what it's doing?Well, the best place to start is probably w3.org:

http://www.w3.org/Style/XSL/

It's pretty hairy stuff though. Most computer book stores have several shelves full of XSL/XSLT books. Since most of them seem to be somewhere around 1000 pages for the 'getting started' volume I fear they are not for the faint of heart. <g>

jgr
09-11-2005, 10:38 AM
Hmmm... it may be even harder considering the coding on that W3 page!

ktinkel
09-11-2005, 11:43 AM
Hmmm... it may be even harder considering the coding on that W3 page!Oooh — very confidence-inspiring! (Not.)

jgr
09-11-2005, 02:15 PM
Oooh — very confidence-inspiring! (Not.)
And of all places to foul up -- w3.org. Geez... (Then again I suppose I can always feel better about my own CSS -- hey, if w3.org can't get it right, who am I to think I can???)

ktinkel
09-11-2005, 04:24 PM
And of all places to foul up -- w3.org. Geez... (Then again I suppose I can always feel better about my own CSS -- hey, if w3.org can't get it right, who am I to think I can???)Good question.

I think you should rest easy! <g>

jgr
09-11-2005, 04:46 PM
I think you should rest easy! <g>It's kind of like how I never worry about being criticized by my boss for making a typographical error in any book I work on. At least not since HE misspelled the word "Jersey". On the cover of a book.

ktinkel
09-11-2005, 04:49 PM
It's kind of like how I never worry about being criticized by my boss for making a typographical error in any book I work on. At least not since HE misspelled the word "Jersey". On the cover of a book.Oh, no! (Picture me falling over!)

Of course, designers and typographers know that the typo not found is always in a headline. But the ones on covers are usually found. Usually.

jgr
09-11-2005, 08:06 PM
Oh, no! (Picture me falling over!)Now get this. (This is even better than the mistake.)

About a month after that book was published (and we update our books annually, and publish in paperback), we got a call from a little girl (term chosen deliberately) who was clerking for one of the Justices of our state Supreme Court.

"Um," she said, "we noticed you had a typo on the cover of the criminal code book."
(Yeah, we know.)

"We didn't say anything then."
(We appreciate that.)

"But then we ordered another copy and..."
(You're not really going to say what I think you're going to say, are you?)

"...and that book had the same typo!"
(Right... we have a bunch of monks sitting in a back room scribing each copy one by one in calligraphy...)

Ian Petersen
09-11-2005, 09:05 PM
And of all places to foul up -- w3.org
Hmm. It doesn't look like that here using Opera or IE. Seems to be a Mozilla thing. As far as I can see both the page and the CSS are valid and correct. Mozilla interprets margin and padding on bullet-lists slightly differently than IE or Opera - the spec is actually unclear on this - although the W3 should probably know that! But in defence of the W3 the email addresses sticking out on the right of the sidebar is actually correct CSS behaviour when something won't fit in a box.

donmcc
09-11-2005, 09:47 PM
hey, if w3.org can't get it right, who am I to think I can???)

If indeed it is their mistake, and not a browser not reacting correctly to a code.

Don McCahill

ktinkel
09-12-2005, 06:01 AM
"...and that book had the same typo!"
(Right... we have a bunch of monks sitting in a back room scribing each copy one by one in calligraphy...)I would laugh (well, I did). But most “civilians” have only a dim understanding of the commercial printing process. She probably figured you just spit another copy out of your ultra-special laser printer right there in the office!

gary
09-12-2005, 03:21 PM
I just happen to be deep in the bowels of an XML-Schema project...

Set the variable "family" to a list of all families with at least one child:
<xsl:variable name="family" select="family[count(child)>0]"/>
If there are any families selected do ...
<xsl:if test="$family">
...
</xsl:if>
Iterate through the list of families, setting the default context to the currently selected family and performing ... in that context
<xsl:for-each select="$family">
...
</xsl:for-each>
Select the string $strchild ("Child") or $strchildren ("Children") based upon whether there is exactly one child in the family
<xsl:choose>
<xsl:when test-"count($children)=1">
<xsl:value-of select="$strchild" .../>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$strchildren" .../>
</xsl:otherwise>
</xsl:choose>

jgr
09-12-2005, 06:52 PM
I just happen to be deep in the bowels of an XML-Schema project...
That's very helpful! Is there any resource you can recommend to help me learn this stuff? The fellow who writes the program is helpful but doesn't seem to be willing to roll back some changes he made in the latest version and it's doing things I do NOT like.

gary
09-13-2005, 03:46 PM
Is there any resource you can recommend to help me learn this stuff?
Techie that I am, I start with the W3 XSL documentation (http://www.w3.org/Style/XSL/). Note the tutorial links (in particular for XSL-FO) at the upper right.

jgr
09-13-2005, 05:20 PM
Techie that I am, I start with the W3 XSL documentation (http://www.w3.org/Style/XSL/). Note the tutorial links (in particular for XSL-FO) at the upper right. Thanks. I will start working through those once I get a few minutes (or a round tuit...).

ktinkel
09-13-2005, 05:56 PM
Thanks. I will start working through those once I get a few minutes (or a round tuit...).And then you can tell the rest of us for when we get a round tuit!

I though PHP was opaque. Sigh. It just gets better and better! (Remember when HTML seemed like a challenge? Maybe not, in your case — but I do.)

donmcc
09-13-2005, 07:16 PM
(Remember when HTML seemed like a challenge? Maybe not, in your case — but I do.)

I lucked out on that one. I was the staffer in a typeshop in the late 80s that was given the job of keeping up on technology, and got all the SGML information that came out around that time. When HTML came out it was a breeze compared to the full SGML.

I have to admit that I am not up on XSL as much as I should be ... I thought it was simply style sheets form XML. To find there is some programming capability within it seems very interesting, and I will have to find some time to delve into it.

Don McCahill

jgr
09-14-2005, 05:14 AM
I though PHP was opaque. Sigh. It just gets better and better! (Remember when HTML seemed like a challenge? Maybe not, in your case — but I do.)HTML has always seemed to me to be very simple -- it works the same way my mind does. PHP? XSL? Even CSS? It's enough to make me whimper.

jgr
09-14-2005, 05:16 AM
I have to admit that I am not up on XSL as much as I should be ... I thought it was simply style sheets form XML. To find there is some programming capability within it seems very interesting, and I will have to find some time to delve into it.Oh good. Then I'll have someone else to ask when I don't understand it...

ktinkel
09-14-2005, 05:48 AM
HTML has always seemed to me to be very simple -- it works the same way my mind does. PHP? XSL? Even CSS? It's enough to make me whimper.Now, now — no whimpering!

My main reaction to HTML was Whew — at least it’s not SGML! And I agree — if you use it the way it was originally intended, it’s utterly logical. Big ideas get big letters, less important get smaller. That makes perfect sense.

But perhaps because I was used to stylesheets for page layout, CSS also seems logical to me. Columns, though, are close to a perversion in either system. That’s why they are so difficult — we have to finagle something to get them to work.

Thinking further: Whimpering is called for for PHP and XSL (and I’m not exactly looking forward to XML, either!).

jgr
09-14-2005, 07:37 PM
Thinking further: Whimpering is called for for PHP and XSL (and I’m not exactly looking forward to XML, either!).Actually, the XML part of the program I'm dealing with seems to make sense. It simply identifies specific strings and you can change 'em there. The XSL might as well be Greek or some other language I never even had a chance to learn. And being short on time does NOT help (the fall semester is well underway so I (a) have one full-time job, (b) teach part-time at the law school, (c) serve as faculty advisor to the Moot Court Board and (d) got hornswoggled into editing a major family chronicles project for the descendants of Davis Davenport (c 1655 - c 1735).

ktinkel
09-15-2005, 04:56 AM
Actually, the XML part of the program I'm dealing with seems to make sense. It simply identifies specific strings and you can change 'em there.Yes, but it is really, really strict. And as far as I can tell, unlike HTML, there is very little understood by default. So you need to declare every jot and tittle, including a few that would never occur to me.

short on time does …Yikes! They say the devil makes work for idle hands — guess you are perfectly safe! <g>

jgr
09-15-2005, 06:36 AM
[XML] is really, really strict. And as far as I can tell, unlike HTML, there is very little understood by default. So you need to declare every jot and tittle, including a few that would never occur to me.Got it. I'll have to get a book on that too. Sigh... so many books, so little time...

ktinkel
09-15-2005, 07:54 AM
Got it. I'll have to get a book on that too. Sigh... so many books, so little time...Yeah! Tell me about it!

And so many books, so little space!

Although, I do see a bunch of out-of-date books (especially books on HTML and old versions of software) that really are no use. I could definitely use the space more than their company — but need time to go through and root them out.

jgr
09-15-2005, 10:10 AM
Notice the common thread here -- NOT ENOUGH TIME!!!! Lord, I want to retire. Like yesterday. I have so many things I want to do, and this working for a living bit is definitely interfering...

ktinkel
09-15-2005, 11:28 AM
Notice the common thread here -- NOT ENOUGH TIME!!!! Lord, I want to retire. Like yesterday. I have so many things I want to do, and this working for a living bit is definitely interfering...And I have essentially retired, and still don’t have time to do what I want. (Hate to discourage you!)

Tempus fugit!

jgr
09-15-2005, 02:58 PM
And I have essentially retired, and still don’t have time to do what I want. (Hate to discourage you!) Tempus fugit!I've been told to expect that, but I s-u-u-u-u-u-u-r-e would like to find out for myself. (And if the stock market doesn't crash, I may be able to do it by the time I'm 65 too!)

ktinkel
09-15-2005, 04:56 PM
I've been told to expect that, but I s-u-u-u-u-u-u-r-e would like to find out for myself. (And if the stock market doesn't crash, I may be able to do it by the time I'm 65 too!)Hrrrrmph. I am only 64-1/2, I’ll have you know!!

And as for the stock market crashing, buy bonds! <g>

dthomsen8
09-19-2005, 07:00 AM
Although, I do see a bunch of out-of-date books (especially books on HTML and old versions of software) that really are no use. I could definitely use the space more than their company — but need time to go through and root them out.

I took my DOS and old hardware books to recycling, 4 shopping bags worth.

dthomsen8
09-19-2005, 07:03 AM
And I have essentially retired, and still don’t have time to do what I want. (Hate to discourage you!)

Tempus fugit!

I am mostly retired, too, but there is less time to do what I want than a few years ago. Getting married at 64 might have something to do with it, though.

{Can we all say, thread drift?}

Kelvyn
09-19-2005, 08:08 AM
I took my DOS and old hardware books to recycling, 4 shopping bags worth.

I have sold most of mine on Ebay!! Some people are interested in history.

ktinkel
09-19-2005, 08:58 AM
{Can we all say, thread drift?}We can all say it; I, on the other, can (and will) fix it!

Or I will fix it as soon as I can unravel this monster. <g>

Thanks.

ktinkel
09-19-2005, 09:01 AM
I have sold most of mine on Ebay!! Some people are interested in history.Wow! Maybe I should post a couple of these gems — see if anyone nibbles. Our city doesn’t recycle books, and local charities refuse them (even the library association). I have been reluctant just to dump them.

I have manuals for the first Mac (and several others), for the first version of PageMaker, QuarkXPress, Illustrator, and more. Not to mention many third-party books on these things. Guess it wouldn’t hurt to try.