1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>pi-attribute</title><link rel="stylesheet" type="text/css" href="../reference.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.1"><link rel="home" href="../index.html" title="DocBook XSL Stylesheets: Reference Documentation"><link rel="up" href="generallibrary.html" title="General Library Templates"><link rel="prev" href="length-in-points.html" title="length-in-points"><link rel="next" href="lookup.key.html" title="lookup.key"><link rel="copyright" href="copyright.html" title="License"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">pi-attribute</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="length-in-points.html">Prev</a> </td><th width="60%" align="center">General Library Templates</th><td width="20%" align="right"> <a accesskey="n" href="lookup.key.html">Next</a></td></tr></table><hr></div><div class="refentry" title="pi-attribute"><a name="pi-attribute"></a><div class="titlepage"></div>
<div class="refnamediv"><h2>pi-attribute</h2><p>
pi-attribute
— Extract a pseudo-attribute from a PI
</p></div>
<div class="refsect1" title="Description"><a name="id36258381"></a><h2>Description</h2>
<p>The <code class="function">pi-attribute</code> template extracts a pseudo-attribute
from a processing instruction. For example, given the PI
<span class="quote">“<span class="quote"><code class="literal"><?foo bar="1" baz='red'?></code></span>”</span>,</p>
<pre class="programlisting"><xsl:call-template name="pi-attribute">
<xsl:with-param name="pis" select="processing-instruction('foo')"/>
<xsl:with-param name="attribute" select="'baz'"/>
</xsl:call-template></pre>
<p>will return <span class="quote">“<span class="quote">red</span>”</span>. This template returns the first matching
attribute that it finds. Presented with processing instructions that
contain badly formed pseudo-attributes (missing or unbalanced quotes,
for example), the template may silently return erroneous results.</p>
<a name="pi-attribute.frag"></a><pre class="programlisting">
<xsl:template name="pi-attribute">
<xsl:param name="pis" select="processing-instruction('BOGUS_PI')"></xsl:param>
<xsl:param name="attribute">filename</xsl:param>
<xsl:param name="count">1</xsl:param>
<xsl:choose>
<xsl:when test="$count>count($pis)">
<!-- not found -->
</xsl:when>
<xsl:otherwise>
<xsl:variable name="pi">
<xsl:value-of select="$pis[$count]"></xsl:value-of>
</xsl:variable>
<xsl:variable name="pivalue">
<xsl:value-of select="concat(' ', normalize-space($pi))"></xsl:value-of>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($pivalue,concat(' ', $attribute, '='))">
<xsl:variable name="rest" select="substring-after($pivalue,concat(' ', $attribute,'='))"></xsl:variable>
<xsl:variable name="quote" select="substring($rest,1,1)"></xsl:variable>
<xsl:value-of select="substring-before(substring($rest,2),$quote)"></xsl:value-of>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="pi-attribute">
<xsl:with-param name="pis" select="$pis"></xsl:with-param>
<xsl:with-param name="attribute" select="$attribute"></xsl:with-param>
<xsl:with-param name="count" select="$count + 1"></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</pre>
</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="length-in-points.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="generallibrary.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="lookup.key.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">length-in-points </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> lookup.key</td></tr></table></div></body></html>
|