[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: complex positioning problem

Subject: Re: complex positioning problem
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Wed, 03 Nov 2004 00:02:34 +0100
positioning template
Hi Bruce,

Here's the second issue I've no clue how to solve (beyond Wendell's suggestion about using temporary trees). I assume I may want to somehow create a virtual element in the temporary tree that indicates the position of the unique linkend value in the document (and between citations), but I'm not really sure.

The traffic on this list is quite high, but I believe your question is still open. Wendell noted correctly that your input document doesn't cover all situations. Even more, I think it is just not complex enough for the general problem of numbering citations.


Some considerations:
- the bibliographic information is presumably unordered and is often sorted and numbered in the order that the biblio_refs_ occur. (How do they call this? Inversion of Control? ;)
- the id's in your sample give an impression of the position, but this impression is false


Puzzling on the problem, I came up with some steps to tackle this. I'll try to explain...

Consider the following scenario (the dots represent ordinary text):
  ...........ref b, ref a.......
  .......ref a, ref b...........
  a) author xx, book yy
  b) author zz, website blabla

I think this should be presented like:
  ...........[1,2].......
  .......[2,1]...........
  1] author zz, website blabla
  2] author xx, book yy

Or prehaps one would like the [2,1] to be presented like [1,2] as well..

First of all, the bibliorefs have to be gathered. I did this with an index (xsl:key). After that, the bibliorefs have to be uniquefied to be able to get the position of the first of each distinct biblioref. I gather the unique list in a global variable, which has to be accessed through a node-set function in XSLT 1 (other solutions would be too complex to explain, putting aside maintenance). The detemination of the position is done in a template.

It is probably not the most efficient code, but it works.

Note the msxsl namespace on node-set. I tested it with msxsl, but I guess that replacing the msxsl namespace by the one for exslt common will work just as fine.

Note also that I didn't solve the ordering of the bibliorefs within one citation. That can be done, by gathering the positions in a variable again and doing the sorting magic as you like.

I also didn't solve the ordering of the presentation of the bibliographic info. But this should be equally or less complex as getting the position of the bibliorefs, though I guess it will need some additional (local) variables and node-set calls... Well, I can't do everything for you.. ;)

Grtz,
Geert

XSL:

<?xml version="1.0"?>

<!-- $Id$ -->

<xsl:stylesheet version="1.1"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:d="http://docbook.org/docbook-ng"

    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    extension-element-prefixes="msxsl"
>

<!--+ ==============================================================
    | output
    +-->

  <xsl:output method="xml"
      version="1.0" encoding="utf-8" indent="yes" />

<!--+ ==============================================================
    | indices
    +-->

  <xsl:key name="bibrefs" match="d:biblioref" use="'all'" />
  <xsl:key name="bibrefs" match="d:biblioref" use="@linkend" />
  <xsl:key name="biblio" match="d:mods" use="@ID" />

<!--+ ==============================================================
    | parameters
    +-->

  <xsl:variable name="unique-bibrefs">
    <xsl:for-each select="key('bibrefs', 'all')">
      <xsl:if test="generate-id(.) = generate-id(key('bibrefs', @linkend)[1])">
        <xsl:copy-of select="." />
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>

<!--+ ==============================================================
    | default templates
    +-->

  <xsl:template match="@*|node()">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

<!--+ ==============================================================
    | custom template
    +-->

  <xsl:template match="/">
    <bibrefs>
      <xsl:for-each select="key('bibrefs', 'all')">
        <xsl:copy-of select="." />
      </xsl:for-each>
    </bibrefs>
    <unique-bibrefs>
      <xsl:copy-of select="$unique-bibrefs" />
    </unique-bibrefs>
    <xsl:apply-templates select="node()"/>
  </xsl:template>

  <xsl:template match="d:citation">
    <xsl:text>[</xsl:text>
      <xsl:for-each select="d:biblioref">
        <xsl:apply-templates select="." />
        <xsl:if test="not(position() = last())">
          <xsl:text>, </xsl:text>
        </xsl:if>
      </xsl:for-each>
    <xsl:text>]</xsl:text>
  </xsl:template>

  <xsl:template match="d:biblioref">
    <xsl:apply-templates select="." mode="get-bibref-position" />
  </xsl:template>

<!--+ ==============================================================
    | group get-bibref-position
    +-->

  <xsl:template match="d:biblioref" mode="get-bibref-position">
    <xsl:variable name="linkend" select="@linkend" />
    <xsl:for-each select="msxsl:node-set($unique-bibrefs)/*">
      <xsl:if test="@linkend = $linkend">
        <xsl:value-of select="position()" />
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.