Subject: Re: [xsl] trying to set a parameter equal to an elements attribute From: "Noel Golding" <noel@xxxxxxxxxxxxxxx> Date: Wed, 21 Aug 2002 17:57:19 -0400 |
here is a more complete example of what I was trying to accomplish, my previous fragment was very error ridden. sorry I hope this is a litte better. <!--xml file --> <?xml version="1.0"?> <root> <article> <title>Investment Science</title> <section name="executive summary"> <title>Executive Summary</title> <para> Some Text goes here </para> </section> </article> <header volume="8" issuedate="August 19, 2002" number="28" link="08192002" /> </root> <!-- xslt file --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="root"> <xsl:param name="page"><xsl:value-of select="header[@link]" /></xsl:param> <xsl:param name="volume"><xsl:value-of select="header[@volume]" /></xsl:param> <xsl:param name="number"><xsl:value-of select="header[@number]" /></xsl:param> <xsl:param name="issuedate"><xsl:value-of select="header[@issuedate]" /></xsl:param> Excerpts from this week's issue Volume <xsl:value-of select="$volume"/>, Number <xsl:value-of select="$number" />: <xsl:value-of select="issuedate"/> </xsl:template> </xsl:stylesheet> ----- Original Message ----- From: "Mike Brown" <mike@xxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, August 21, 2002 5:22 PM Subject: Re: [xsl] trying to set a parameter equal to an elements attribute > Noel Golding wrote: > > > <!-- XML FILE --> > > > <root> > > > <header volume="8"/> > > > > > > <article> > > > <para> > > > Some text here > > > </para> > > > </article> > > > </root> > > > > > > <!-- XSLT FILE --> > > > <xsl:stylesheet version="1.0" xmlns:xsl=""> > > > <xsl:template match="root"> > > > <xsl:param name="vol"><xsl:value-of select="header[@volume]"/> > > > </xsl:template> > > > </xsl:stylesheet> > > 1. you need to put the XSLT namespace name in the xmlns:xsl > > 2. xsl:variable and xsl:param create a new object and give it a name. > xsl:value-of creates a text node, unless there is no text to create. > > Assuming you meant to put </xsl:param> after the value-of, what you did was > try to set $vol to whatever value for it was passed into the template. None > was (unless there's more to your stylesheet), so $vol was instead set to be a > new object of type "result tree fragment" (which is a non-traversable > node-set). This object consisted of a root node with one child: the text node > that was created by xsl:value-of. You created this 'vol' object but you never > made reference to $vol, so you got no output. > > I assume you just wanted > > <xsl:template match="root"> > <xsl:value-of select="header[@volume]"/> > </xsl:template> > > or > > <xsl:template match="root"> > <xsl:variable name="vol" select="header[@volume]"/> > <xsl:value-of select="$vol"/> > </xsl:template> > > or, if you're passing in $vol from outside the stylesheet, but defaulting > it to header[@volume] if it's not passed in, you need a top-level param: > > <xsl:param name="vol" select="/root/header[@volume]"/> > > <xsl:template match="root"> > <xsl:value-of select="$vol"/> > </xsl:template> > > - Mike > ____________________________________________________________________________ > mike j. brown | xml/xslt: http://skew.org/xml/ > denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/ > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] trying to set a parameter, Mike Brown | Thread | RE: [xsl] trying to set a parameter, Dion Houston |
RE: [xsl] trying to set a parameter, Dion Houston | Date | [xsl] Newsgroup?, Joel Konkle-Parker |
Month |