Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 6e019a662639ac6470f50dea3a4d8157 > files > 947

docbook-style-xsl-doc-1.79.2-4.mga7.noarch.rpm

<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>pi-attribute</title><link rel="stylesheet" type="text/css" href="../reference.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.2"><link rel="home" href="../index.html" title="DocBook XSL Stylesheets: Reference&nbsp;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>&nbsp;</td><th width="60%" align="center">General Library Templates</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="lookup.key.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="pi-attribute"></a><div class="titlepage"></div><div class="refnamediv"><h2>pi-attribute</h2><p>pi-attribute &#8212; Extract a pseudo-attribute from a PI</p></div><div class="refsect1"><a name="d0e33383"></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">&#8220;<span class="quote"><code class="literal">&lt;?foo bar="1" baz='red'?&gt;</code></span>&#8221;</span>,</p><pre class="programlisting">&lt;xsl:call-template name="pi-attribute"&gt;
  &lt;xsl:with-param name="pis" select="processing-instruction('foo')"/&gt;
  &lt;xsl:with-param name="attribute" select="'baz'"/&gt;
&lt;/xsl:call-template&gt;</pre><p>will return <span class="quote">&#8220;<span class="quote">red</span>&#8221;</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">
&lt;xsl:template name="pi-attribute"&gt;
  &lt;xsl:param name="pis" select="processing-instruction('BOGUS_PI')"&gt;&lt;/xsl:param&gt;
  &lt;xsl:param name="attribute"&gt;filename&lt;/xsl:param&gt;
  &lt;xsl:param name="count"&gt;1&lt;/xsl:param&gt;

  &lt;xsl:choose&gt;
    &lt;xsl:when test="$count&gt;count($pis)"&gt;
      &lt;!-- not found --&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:variable name="pi"&gt;
        &lt;xsl:value-of select="$pis[$count]"&gt;&lt;/xsl:value-of&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:variable name="pivalue"&gt;
        &lt;xsl:value-of select="concat(' ', normalize-space($pi))"&gt;&lt;/xsl:value-of&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="contains($pivalue,concat(' ', $attribute, '='))"&gt;
          &lt;xsl:variable name="rest" select="substring-after($pivalue,concat(' ', $attribute,'='))"&gt;&lt;/xsl:variable&gt;
          &lt;xsl:variable name="quote" select="substring($rest,1,1)"&gt;&lt;/xsl:variable&gt;
          &lt;xsl:value-of select="substring-before(substring($rest,2),$quote)"&gt;&lt;/xsl:value-of&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:call-template name="pi-attribute"&gt;
            &lt;xsl:with-param name="pis" select="$pis"&gt;&lt;/xsl:with-param&gt;
            &lt;xsl:with-param name="attribute" select="$attribute"&gt;&lt;/xsl:with-param&gt;
            &lt;xsl:with-param name="count" select="$count + 1"&gt;&lt;/xsl:with-param&gt;
          &lt;/xsl:call-template&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;
</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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="generallibrary.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="lookup.key.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">length-in-points&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;lookup.key</td></tr></table></div></body></html>