|
Subject: Re: [xsl] want to sort and resolve <xref> values in one pass (XSL-FO) From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 2 Aug 2014 15:24:49 -0000 |
Charles,
You can do this using a technique called micro-pipelining.
In the template where the fo:block[@id="REFERENCES"] is generated, in
your first stylesheet, capture the block (I am assuming below that it
is generated by a call to apply templates) in a variable:
<xsl:template match="whatever">
<xsl:variable name="ref-block">
<xsl:apply-templates or whatever generates your REFERENCE block />
</xsl:variable>
... and then process the block in the variable in a second pass ...
<xsl:apply-templates select="$ref-block/fo:block"/>
</xsl:template>
The second call to apply templates will be given the task of sorting
them. Since this logic is already in templates in your post-processing
stylesheet, you should be able to copy them into the main stylesheet
and be done.
Take care when doing this that you do not have other templates
matching fo:block and its ilk; if you do, you need to use modes to
avoid template collisions. (This might be a good idea in any case, if
only to clarify for maintenance what is going on.)
I hope this helps.
Cheers, Wendell
On Wed, Jul 30, 2014 at 5:49 PM, Flanders, Charles E (US SSA)
charles.flanders@xxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> I am currently using a two-step process to sort a list of cross references
in an FO file. I run the pub through my XSL-FO style sheets, then run my
resultant FO file through a second XSLT (FO to FO) to sort the results of
resolved cross references.
>
> I have a list of cross references the looks like this:
>
> <ref>
> <ref-setup-item>
> <xref wpid="t2034592355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2001792355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2002292355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2004392355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2087492355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2087692355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2078292355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2078392355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2078692355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2110492355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2078892355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2085792355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2002492355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2002992355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2003292355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2089592355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2089692355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2089792355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2003592355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2003692355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2003492355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2003792355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2100192355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2003992355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2004092355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2004192355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2100092355314"/>
> </ref-setup-item>
> <ref-setup-item>
> <xref wpid="m2033692355314"/>
> </ref-setup-item>
> </ref>
>
> The FO output is this:
>
>
>
> <fo:block widows="2" orphans="2"
space-before.minimum="6pt" space-before.optimum="7pt"
> space-before.maximum="8pt"
> space-after.minimum="0pt"
> space-after.optimum="0pt"
> space-after.maximum="1pt"
> span="none" role="REFERENCES">
> <fo:block font-weight="bold"
keep-with-next.within-column="always">References</fo:block>
> <fo:block font-weight="normal"
keep-with-previous.within-column="always" span="none"
> start-indent="12pt"
> text-align="left">
> <fo:basic-link>Vol. 4, WP 0313</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left"
> keep-with-previous.within-column="always">
> <fo:basic-link>Vol. 8, WP 0598</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 9, WP 0772</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0681</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0613</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0635</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0645</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0646</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 9, WP 0773</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0647</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0654</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0632</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0639</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0655</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0662</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0663</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0664</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0665</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0667</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0668</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0634</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0666</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0642</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0674</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0675</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 8, WP 0676</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 10, WP 0926</fo:basic-link>
> </fo:block>
> <fo:block font-weight="normal" span="none"
start-indent="12pt" text-align="left">
> <fo:basic-link>Vol. 10, WP 0988</fo:basic-link>
> </fo:block>
> </fo:block>
>
> Currently I run a second XSLT (below> to sort the FO output.
>
> <xsl:template match="fo:block[@role='REFERENCES']">
> <fo:block widows="2" orphans="2" space-before.minimum="6pt"
space-before.optimum="7pt" space-before.maximum="8pt"
space-after.minimum="0pt" space-after.optimum="0pt" space-after.maximum="1pt"
span="none" role="REFERENCES">
> <xsl:copy-of select="child::fo:block[1]"/>
> <xsl:apply-templates select="child::fo:block[position() >
1]">
> <xsl:sort
select="substring-after(fo:basic-link/text(),'WP')"/>
> </xsl:apply-templates>
> </fo:block>
> </xsl:template>
>
> Instead of running the second XSLT, I want to perform the sort with the
initial style sheet run. I know I can capture the unsorted output into a
variable, but where I'm having trouble is sorting the contents (value) of the
variable and then writing out the sorted output. What I have so far (and this
is just a snippet of a much larger XSL-FO style sheet of nearly 80 modules).
>
> <xsl:template match="ref">
> <fo:block space-before.maximum="8pt"
space-before.minimum="6pt" space-before.optimum="7pt" span="none"
xsl:use-attribute-sets="wpinfosub">
> <fo:block font-weight="bold"
keep-with-next.within-column="always">
> <xsl:text>References</xsl:text>
> </fo:block>
> <xsl:variable name="REFS">
> <xsl:apply-templates
select="child::ref-setup-item"/>
> </xsl:variable>
> <xsl:apply-templates select="$REFS">
> <xsl:sort
select="substring-after(child::basic-link/text(),'WP')"/>
> </xsl:apply-templates>
> </fo:block>
> </xsl:template>
>
>
> The above does not work. I do know that the value of $REFS is correct in
that I've used <xsl-copy-of select="$REFS" to verify the value or contents of
$REFS. How I do sort the value of $REFS and put it into the output? Using the
above is outputting the <fo:root> and <fo:layout-master-set>, then "value-of"
(just text) $REFs with no FO markup. What am I missing?
>
>
> C Flanders
>
>
--
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Replacing = with == and =, Graydon graydon@xxxx | Thread | [xsl] Merging common tags of 2 xml , varun bhatnagar varu |
| Re: [xsl] Replacing = with == and =, L2L 2L emanuelallen@ | Date | Re: [xsl] Replacing = with == and =, Bridger Dyson-Smith |
| Month |