Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Question? Better Way?

From: Mark Johnson <102334.12@----------.--->
To: NULL
Date: 6/4/2004 8:18:00 AM
I wanted a shorthand for adding external links to a document. So I
markup the document, by hand, with "<link>" elements. And when I push
a button, it is combined with other things to produce an XML. And then
an XSLT is applied to that to produce HTML output. Let's say I have as
that first stage XML:

<a1>
	<descrip>
		<blockquote>
			Who'll
			<em>
				stop the rain? 
				<linebreak/>
				Performed by:
				<link/>
			</em>
			<linebreak/>
			reference [
			<link n="20"/>
			,
			<link>link3b</link>
			,
			<link n="10">backto1</link>
			].
		</blockquote>
		<insertLink>
			<name>link1</name>
			<url>http://link1.com</url>
			<num>10</num>
		</insertLink>
		<insertLink>
			<name>link2</name>
			<url>http://link2.com</url>
			<num>20</num>
		</insertLink>
		<insertLink>
			<name>link3</name>
			<url>http://link3.com</url>
			<num>25</num>
		</insertLink>
	</descrip>
</a1>


And have it come out from the XSLT:

	Who'll	<em>stop the rain? 
	<br>&#160;<br>
	Performed by:	<a href="http://link1.com">link1</a></em>
	<br>&#160;<br>
	reference [<a href="http://link2.com">link2</a>,<a
href="http://link3.com">link3b</a>,<a
href="http://link1.com">backto1</a>].


In other words, for each "descrip" node, read out the insertLink info
either in list order, or by "num" key, and then just discard the
insertLink's. If the link has text, use that. Otherwise, use the
"name" from the link as the text for that link.

I wonder if I'm missing something, and that there might be a better
way to proceed, either with the design, above, or the XSLT, below:


<xsl:template match="link[ancestor::descrip/insertLink]">

	<xsl:variable name="linkpos">
		<xsl:choose><xsl:when test="@n">
			<xsl:variable name="linknum" select="@n"/>
			<xsl:value-of
select="count(ancestor::descrip/insertLink[./num &lt;= $linknum])"/>
		</xsl:when><xsl:otherwise>
			<!-- position() reports non-"link" siblings: use count()
-->
			<xsl:value-of
select="count(self::*/preceding-sibling::link)+1"/>
		</xsl:otherwise></xsl:choose>
	</xsl:variable>
	<xsl:variable name="uselink"
select="ancestor::descrip/insertLink[position()=$linkpos]/url"/>

	<xsl:choose>
		<xsl:when test="text()">
			<a href="{$uselink}"><xsl:value-of select="text()"/></a>
		</xsl:when><xsl:otherwise>
			<a href="{$uselink}">
			<xsl:value-of
select="ancestor::descrip/insertLink[position()=$linkpos]/name"/></a>
		</xsl:otherwise></xsl:choose>

</xsl:template>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent