title: XSLT, XML: Getting the number of a step or figure for cross-references
body: <p>I'm working on XSLT to display an XML document (a section of a user manual) as HTML.  For figures, I have the following XSLT template:</p>
  
  <pre><code>&lt;xsl:template match = "figure"&gt;
      &lt;a&gt;
          &lt;xsl:attribute name = "name"&gt;
              &lt;xsl:value-of select = "./@id"/&gt;
          &lt;/xsl:attribute&gt;
          &lt;p class = "caption"&gt;Figure &lt;xsl:number count="figure"/&gt;: &lt;xsl:value-of select="./title"/&gt;&lt;/p&gt; 
          &lt;p class = "graphic"&gt;
              &lt;img style="width:700px;"&gt;
                  &lt;xsl:attribute name = "src"&gt;
                      &lt;xsl:value-of select = "./graphic/@boardno"/&gt;
                  &lt;/xsl:attribute&gt;
              &lt;/img&gt;
          &lt;/p&gt;
      &lt;/a&gt;
   &lt;/xsl:template&gt;
  </code></pre>
  
  <p>This displays the figure and gives it a number based on its position in the document.  Right now, the template I have for figure references (&lt; figref >) is this:</p>
  
  <pre><code>&lt;xsl:template match = "figref"&gt;
       &lt;a&gt;
       &lt;xsl:attribute name = "href"&gt;
           #&lt;xsl:value-of select = "./@IDREF" /&gt;
       &lt;/xsl:attribute&gt;
       &lt;span class = "figure&gt;
      &lt;xsl:value-of select = "."/&gt;   
       &lt;/span&gt;
       &lt;/a&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Here's the XML itself:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;?xml-stylesheet type="text/xsl" href="lorip.xsl"?&gt;
      &lt;descopim docid="LoremIpsumSample" &gt;
          &lt;descwp id ="descwp_LorIp"&gt;
              &lt;titleblk&gt;
                     &lt;wptitle&gt;
                      &lt;maintlvl&gt;Dolor Sit Amet&lt;/maintlvl&gt;
                      &lt;subject&gt;Natoque Page - Description and Controls&lt;/subject&gt;
                      &lt;sysnomen&gt;
                          &lt;name&gt;Lorem Ipsum&lt;/name&gt;
                      &lt;/sysnomen&gt;
                  &lt;/wptitle&gt;  
              &lt;/titleblk&gt;
  &lt;intro&gt;
              &lt;title&gt;Nunc Eget ut Vivamus&lt;/title&gt;
              &lt;para id="NuncEgVivpara001"&gt;
                  Lorem ipsum dolor sit amet, dui eu, est natoque suscipit suspendisse fringilla et. Adipisicing nonummy, urna in justo. 
                  Maecenas sollicitudin nam ut a asperiores mollis. Nunc eget ut ut vivamus, sit mollis integer purus amet. Consequat 
                  molestie pellentesque, ultricies tincidunt elit arcu nullam diam, in tempor morbi integer.
              &lt;/para&gt;
          &lt;/intro&gt;
          &lt;sysdesc&gt;
              &lt;title&gt;Nunc Eget Luctus Nullam&lt;/title&gt;
              &lt;desc&gt;
                  &lt;para&gt;
                      Neque eu maecenas pellentesque metus, gravida convallis est orci
                      &lt;figref IDREF = "ConvEstOrcifig001" label = "Convallis est Orci"&gt;Figure &lt;/figref&gt; sollicitudin nam ut a asperiores mollis,  
                      &lt;figref IDREF = "AsperMollfig002" label = "Asperiores Mollis"&gt;  Figure &lt;/figref&gt;.           
                      Amet nostra mus aptent ut commodo. Platea vestibulum vitae non felis, sed ac. Morbi quam tortor vestibulum lorem fringilla 
                      nec. Enim sed taciti dictum vehicula sit, risus at vehicula risus wisi quis, fermentum dolor ante illo quis odio at, 
                      dignissim nullam arcu nisl arcu nec ullamcorper, libero vehicula sed. &lt;extref href = "appendixb.pdf"&gt;Appendix B (Adipisicing 
                      Nonummy)&lt;/extref&gt; et &lt;extref href = "appendixc.pdf"&gt;Appendix C (Maecenas sollicitudin) &lt;/extref&gt;.
                  &lt;/para&gt;
              &lt;/desc&gt;
          &lt;/sysdesc&gt;
              &lt;figsect&gt;
                  &lt;figure id = "SuspFringfig001"&gt;
                      &lt;title&gt;Suspendisse Fringilla&lt;/title&gt;
                      &lt;graphic boardno = "SuspFringfig001.png"&gt;&lt;/graphic&gt;
                  &lt;/figure&gt;
                  &lt;figure id = "AsperMollfig002"&gt;
                      &lt;title&gt;Asperiores Mollis &lt;/title&gt;
                      &lt;graphic boardno = "AsperMollfig002.png"&gt;&lt;/graphic&gt;
                  &lt;/figure&gt;
                  &lt;figure id = "VivPulLitfig007"&gt;
                      &lt;title&gt;Viverra Pulvinar Litora&lt;/title&gt;
                      &lt;graphic boardno = "VivPulLitfig007.png"&gt;&lt;/graphic&gt;
                  &lt;/figure&gt;
              &lt;/figsect&gt;
          &lt;/descwp&gt;
      &lt;/descopim&gt;
  </code></pre>
  
  <p>I need a way to pull the number from the figure itself (xsl:number count="figure"), or to identify what number that figure is in the overall order, to display that with the cross-reference (e.g., "Figure 3" rather than just "Figure.")</p>
  
  <p>So, the result I'm looking for, using the first figref as an example, is:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;a href ="#SuspFringfig001"&gt;
    &lt;span class = "figure"&gt;
      Figure 1  
    &lt;/span&gt;
  &lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>