By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

[XSL] generating links to chapter, header, subheaders with autonumeration

P: n/a
Witam,
mam nastepujacy problem:
XSLT 2.0,

Hi,
i've got following problem with xslt 2:

my xml doc looks something linke:

<manual>
<chapter id="intro-some" title="some title23l>
<header id="intro-some-header" title="some titleser3 2">
<part id="jakisid12" title="jakistitle2435">
...
</part>
<part id="jakisid3343" title="jakistitle2345">
...
</part>
</header>
</chapter>

jest dowolna liczba headerow i chapterow, part jest opcjonalny.

there are chapters (non-optional), headers (in chapters) (non-
optional) and parts (in chapters) (optional)

When i'm transforming to html when i create snippet about header,
chapter or part im presenting something like:
"1. title of chapter one" (for chapters), "1.2. title of header
two" (for header two in chapter one), "1.2.4 title of part four" (for
part number four in header number two in chapter number one"

Im using following code (i.e. for part numeration):

<xsl:number level="multiple" count="chapter|header|part"
format="1.1.1 " />

And xml is auto numbering my chapters, headers and parts.

With anything that I wrote for now there are no problems. But i have
new requirement for my xsl transformation.

In my xml inside chapter or header or part i can insert element:
<linkLeech href="jakisIDdoChapterLubHeaderLubPart"/>
which should be replaces (in target document i.e. html) to:
<a href="xxx">1.2.3 title of target part</a(if href is referring
part by id)
or
<a href="xxx">1.2 title of target header </a(if href is referring
header by id)
or
<a href="xxx">1. title of target chapter</a(if href is referring
chapter by id)

And i have a problem: I can read the title of target element(chapter,
header, part) but I can not determine which number should I insert
before title ot target element. At this time I can not determine the
position of target element reffered to other elements (in context-
node)

I hope my description was clear ehough, i will by pleased if someone
with bigger experience than me could help me with this problem, thanks
for all kind of help.

Mar 5 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mar 5, 2:54 pm, jszczepankiew...@gmail.com wrote:
Witam,
mam nastepujacy problem:
XSLT 2.0,
This is an English-speaking newsgroup. There's absolutely
no need to intersperse Polish (or whichever language that
is) with English.
my xml doc looks something linke:
No it doesn't. It's not well-formed. Posting sloppy
examples is largely equivalent to shouting: "I don't want
your help!"
<manual>
<chapter id="intro-some" title="some title23l>
<header id="intro-some-header"
title="some titleser3 2">
<part id="jakisid12" title="jakistitle2435">
...
</part>
<part id="jakisid3343"
title="jakistitle2345">
...
</part>
</header>
</chapter>

When i'm transforming to html when i create snippet about
header, chapter or part im presenting something like:
"1. title of chapter one" (for chapters), "1.2. title of
header two" (for header two in chapter one), "1.2.4 title
of part four" (for part number four in header number two
in chapter number one"
[xsl:number problems]

Here's a little something for you to chew on:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:usr="http://example.org/usr">
<xsl:function name="usr:num">
<xsl:param name="elt"/>
<xsl:choose>
<xsl:when test="not($elt/parent::*)"/>
<xsl:when
test="$elt[self::chapter|self::header|self::part]">
<xsl:value-of select="usr:num($elt/parent::*)"/>
<xsl:value-of
select=
"
count
(
$elt/preceding-sibling::chapter|
$elt/preceding-sibling::header|
$elt/preceding-sibling::part
)+1
"/>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="usr:num($elt/parent::*)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="usr:tag">
<xsl:param name="elt"/>
<xsl:value-of select="usr:num($elt)"/>
<xsl:text</xsl:text>
<xsl:value-of select="$elt/@title"/>
</xsl:function>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*"/>
<xsl:template match="chapter|header|part">
<xsl:value-of select="usr:tag(.)"/>
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
</xsl:stylesheet>

--
Pavel Lepin

Mar 5 '07 #2

P: n/a
first I want to apologise for inclusion of my mother language, I was
posting it to second group and was in hurry and do not deleted ...
nevermind.
Someone helped me and it was so simple, take a look:
<xsl:template match="linkLeech">
<xsl:for-each select="//*[@id=current()/@href]">
<xsl:number level="multiple" count="chapter|header|part"
format="1.1.1" />
....

Thanks for all help, i will take a look at your suggestions.

Mar 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.