Subject: AW: [xsl] Newbie - Please help From: Markus Abt <abt@xxxxxxxx> Date: Thu, 31 Jul 2003 19:14:32 +0200 |
Hello Joseph, I cannot discover what your xslt has to do with your xml, but to output your xml as desired you can do something like (I assume for the B2 and B3 elements to be directly contained in some element A): <xsl:template match="A"> <xsl:apply-templates select="B2"/> </xsl:template> <xsl:template match="B2"> <xsl:variable name="pos" select="position()"/> <xsl:variable name="url" select="following-sibling::B3[$pos]"/> <xsl:value-of select="."/> <xsl:text> (</xsl:text> <a href="{$url}"> <xsl:value-of select="$url"/> </a> <xsl:text>)</xsl:text> <xsl:if test="position()!=last()"> <xsl:text>, </xsl:text> </xsl:if> </xsl:template> Note that you cannot change a variable's value inside a template, as you tried in your (at least therefore not working) stylesheet fragment. So I introduced a template for element B2, and then use the variable $url exactly one time on each run through the template to query the relating url content. I used a second (the first) variable $pos to store the position of the B2 element, as the position() function inside the predicate for B3 as in "following-sibling::B3[position()]" would correspond to the B3's position, not to B2's. Hope this helps, Markus __________________________ Markus Abt Comet Computer GmbH http://www.comet.de ---------- Von: Joseph Tan Gesendet: Donnerstag, 31. Juli 2003 16:51 An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Betreff: [xsl] Newbie - Please help Here's part of my xml output <B2>MDConsult</B2> <B2>Elsevier</B2> <B3>http://home.mdconsult.com</B3> <B3>http://www.sciencedirect.com</B3> I would like my display to be: MDConsult (Full-Text), Elsevier (Full-Text) {Note: The "Full-Text" link will link to the correspondent URL.} Right now, the display is as follows: MDConsult, Elsevier; http://home.mdconsult.com, http://www.sciencedirect.com Here is is part of my XSL code: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <xsl:template name="DisplayRemainder"> <xsl:param name="items"/> <xsl:variable name="separator1" select="', '"/> <xsl:variable name="separator2" select="'; '"/> <br/> <xsl:choose> <xsl:when test="DBN='Library catalog'"> Holdings: <xsl:for-each select="$items"> <xsl:call-template name="DisplayItem"/> <xsl:if test="position() != last()"> <xsl:variable name="pos" select="position()"/> <xsl:variable name="next" select="$items[$pos+1]"/> <xsl:choose> <xsl:when test="name() = name($next)"><xsl:value-of select="$separator1"/></xsl:when> <xsl:otherwise><xsl:value-of select="$separator2"/></xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:for-each select="$items"> <xsl:call-template name="DisplayItem"/> <xsl:if test="position() != last()"> <xsl:variable name="pos" select="position()"/> <xsl:variable name="next" select="$items[$pos+1]"/> <xsl:choose> <xsl:when test="name() = name($next)"><xsl:value-of select="$separator1"/></xsl:when> <xsl:otherwise><xsl:value-of select="$separator2"/></xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="DisplayItem"> <xsl:value-of select="."/> </xsl:template> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thanks in advance for helping! Joseph Tan UT Southwestern Medical Center 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 -> |
---|---|---|
[xsl] Controlling Sequence of Outpu, Joseph Tan | Thread | AW: [xsl] '<' and '>' in the value , Markus Abt |
RE: [xsl] Including/Importing a sty, Robert Koberg | Date | Re: [xsl] '<' and '>' in the value , Mukul Gandhi |
Month |