xsl-list
[Top] [All Lists]

Re: variable question

2004-11-10 11:18:59
Bruce,

You can't do this. A parallel thread is also on the topic of using XPaths dynamically like this, and how it can't be done in XSLT 1.0.

The XPath "//$bibkey" doesn't make any sense to the processor, since an XPath step (the part between the slashes, or after the '//' abbreviation in this case) can't be a variable reference, but must be a combination of axis, node test and (optional) predicates. This is because there can be no guarantee that a variable reference will resolve to anything useful. Here it doesn't even resolve to a string, much less to the string "db:biblioref/@linkend", since the variable hasn't been bound to that string, but rather to the node-set retrieved by that string in the context of the variable declaration (which happens to be an empty node set in this case, since your document has no db:biblioref/@linkend navigating from the root, which is the context of the declaration).

An analogy might be if you got a bill from the electric company, but instead of putting a payment in the envelope and sending it back, you put in a note that said "mail this back and I'll send a check to put in this envelope". Sorry, the electric company can't credit your account on that basis.

(Just as the electric company has to cash your check before they can be paid, the stylesheet engine has to compile your stylesheet before it can be executed. Your variable reference doesn't give it the information it needs to compile, just as your IOU can't be cashed as if it were a check -- even if you happen to be good for the money.)

In XSLT 1.0 the only way to do this would be by using a stylesheet to generate your stylesheet. Maybe Mike or Jeni or someone can suggest an easier way to do this in XSLT 2.0.

Cheers,
Wendell

At 11:25 AM 11/10/2004, you wrote:
Why does my below __variable not seems to work, while if I use the same xpath expression in place of it, it does? How can I fix this to use the variable? I just want to localize in one place the configuration for where to find the data (in the below case, on the file system, in a directory called "bib-data", where each reference is in an individual file named with the value of the citation ID).

Bruce

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
   xmlns:mods="http://www.loc.gov/mods/v3";
   xmlns:db="http://docbook.org/docbook-ng";
   exclude-result-prefixes="db mods">

   <xsl:output method="xhtml" encoding="UTF-8" />

   <xsl:variable name="bibkey" select="db:biblioref/@linkend" />
<xsl:variable name="bibrecord" select="doc(concat('bib-data/', $bibkey, '.mods'))" />

   <xsl:template match="/">
      <html xmlns="http://www.w3.org/1999/xhtml";>
         <head>
            <title>Testing</title>
         </head>
         <body>
            <h3>Citations</h3>
            <xsl:for-each select="//$bibkey">
               <ol>
                  <li><xsl:value-of select="." /></li>
               </ol>
            </xsl:for-each>
            <h3>Titles</h3>
            <xsl:for-each select="//$bibkey">
               <xsl:value-of select="$bibrecord//mods:title" />
            </xsl:for-each>
         </body>
      </html>
   </xsl:template>

</xsl:stylesheet>

Source example:

<?xml version="1.0" encoding="utf-8"?>
<article xmlns="http://docbook.org/docbook-ng";>
  <info>
    <title>Test</title>
  </info>
  <section>
    <info>
      <title>Introduction</title>
    </info>
    <para>Some citations: <citation><biblioref linkend="one"/><biblioref
    linkend="two"/><biblioref linkend="three"/></citation>.</para>
<para>A citation with page number detail: <citation><biblioref linkend="one"
    units="page" begin="23" end="24" /></citation>. A
    citation <footnote><para>... in a footnote <citation><biblioref
    linkend="three" begin="234"/></citation></para></footnote>.</para>
  </section>
  <bibliography/>
</article>


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================



<Prev in Thread] Current Thread [Next in Thread>