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

  • Thread starter jszczepankiewicz
  • Start date
J

jszczepankiewicz

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.
 
P

p.lepin

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:eek:therwise>
<xsl:value-of select="usr:num($elt/parent::*)"/>
</xsl:eek:therwise>
</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>
 
J

jszczepankiewicz

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top