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

Discussion in 'XML' started by jszczepankiewicz@gmail.com, Mar 5, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Guest

    Re: generating links to chapter, header, subheaders with autonumeration

    On Mar 5, 2:54 pm, 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: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>

    --
    Pavel Lepin
     
    , Mar 5, 2007
    #2
    1. Advertising

  3. Joseph Kesselman, Mar 5, 2007
    #3
  4. Guest

    Re: generating links to chapter, header, subheaders with autonumeration

    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, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. spammy

    Subheaders in Datagrid?

    spammy, Jun 10, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,796
    spammy
    Jun 11, 2004
  2. Matthias
    Replies:
    0
    Views:
    546
    Matthias
    Aug 8, 2006
  3. =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=

    subheaders with totals for each

    =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=, Oct 16, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    793
    Steven Cheng[MSFT]
    Oct 18, 2006
  4. igotyourdotnet

    subheaders with totals

    igotyourdotnet, Nov 4, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    395
    Steven Cheng[MSFT]
    Nov 12, 2006
  5. Bit byte
    Replies:
    1
    Views:
    657
    benben
    Apr 19, 2006
Loading...

Share This Page