l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2003 Dec 17 12:03

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] XSLT questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] XSLT questions



On Tue, Dec 16, 2003 at 01:46:50PM -0800, Jonathan McPherson wrote:
> Micah,
> 
> > That would not make valid XHTML (assuming you're generating XHTML
> > 1.). Your <xsl:stylesheet> opening tag should contain something like:
> >
> >   xmlns="http://www.w3.org/1999/xhtml";
> 
> It was, in fact, the XHTML validator that made me realize that I had a
> problem in the first place.  I had the xmlns string in the stylesheet
> earlier, but had removed it for some reason.  I put it back and, like
> magic, I have validating XHTML code.  Thanks!
> 
> > Some processors provide extensions to convert a result fragment into a
> > node set; but you should be able to do the same thing in another way
> > (XSLT is Turing complete, after all). You haven't really given much
> > information on what it is you want to achieve: can you give an example
> > of what you're trying to accomplish?
> 
> Well, it isn't a case in which I can't get the result that I want--it's a
> case of not being able to do things in the way I want to, so the fact
> that XHTML is Turing-complete does not guarantee anything.
> 
> Let's say, for instance, that have an XML tag for a project
> description...
> here's a very contrived example:
> 
> <project name="TTP">
> The TTP Project is the only project in our company with a fully
> recursive acronym.
> </project>
> 
> And I want to convert that to the following XHTML:
> 
> <hr />
> <img class="sep" src="pretty.png" alt="" />
> <hr />
> <p><strong>Project name: TTP</strong></p>
> <q>The TTP Project is the only project in our company with a fully
>    recursive acronym.</p>
> 
> This is fine, but suppose that I soon realize that the "sep" image
> surrounded by two <hr /> tags is something I use in many places in my
> stylesheet, and I want to make it a parameterized entity that I can use
> in many settings, like <sepimage src="pretty.png" />.  I don't know how
> to do this in XSLT; it seems that I am doomed to repeat the XHTML in each
> case, since <sepimage ... /> is not part of the source document.  Suppose
> I change my mind and want all these separator images (both those
> separating project descriptions and otherwise) to have one <hr /> rather
> than two--I'll have to go through my stylesheet and find each place where
> I used a separator image and fix it.
> 
> Basically, I want subroutines that I can use to abstract common but
> parametric elements of my stylesheets, and after going through a number
> of XSLT tutorials, I still can't find 'em.

The XSLT equivalent of called subroutines is named templates. You can
do something like (untested):

  <xsl:template name="sep-image">
    <xsl:param name="src"/>
    <hr />
    <img class="sep" src="{$src}" alt="" />
    <hr />
  </xsl:template>

And then you can invoke it with:

  <xsl:call-template name="sep-image">
    <xsl:with-param name="src" value="pretty.png"/>
  </xsl:call-template>

Hope that's what you were looking for. BTW, if you can avoid empty alt
attributes, you should probably parameterize that, too, if your source
XML format supports something that can be used for it. In my custom
DocBook stylesheets, I generate most <img/> elements from docbook
<graphic/> elements; and I use the xreflabel attribute's contents when
available; otherwise the contents of the <title/> sub-element to
<graphic/>.

-- 
Micah J. Cowan
micah@cowan.name
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.