Subject: [xsl] Problems grouping nested items within a completely flat structure From: "Wegmann, Frank frank.wegmann@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 6 Aug 2014 12:53:17 -0000 |
Hi. While there is a lot of information about grouping available, I still have problems applying it to my particular case of a document-centric XML file. Obviously I havenbt yet understood it fully. This is my (redacted) source. Please excuse its length, but this better illustrates my problem. I use Saxon 9HE, but I am open to both, XSL 1.0 or 2.0 solutions. <textflow tftag=bAb> <para pgftag=bChapterb> <paraline>Introduction</paraline> </para> <para pgftag="Body text"> <paraline>This chapter expains...</paraline> </para> <para pgftag="Bulleted text"> <paraline>Display the online help as follows:</paraline> </para> <para pgftag="Bullet sub"> <paraline>To view the help for a panel, press the help (PF1) key.</paraline> </para> <para pgftag="Bullet sub"> <paraline>To view the help for an input field or select a parameter from a pop-up window, </paraline> <paraline>press PF1.</paraline> </para> <para pgftag="Note"> <paraline>If you do not specify a required parameter, or enter an incorrect one, XXXX </paraline> <paraline>will prompt you for the correct information.</paraline> </para> <para pgftag="Bulleted text"> <paraline>Check relevant sections of <render charformat="Emphasis">XXXX</render>.</paraline> </para> <para pgftag="Bulleted text"> <paraline>Visit our web site to get...</paraline> </para> <para pgftag="Body text"> <paraline>The topics covered are:</paraline> </para> <para pgftag="Bulleted text"> <paraline> <xref srctext="55167: 1st Section: What is XXX?"><render charformat="Bold">What is XXX?</render></xref> </paraline> </para> <para pgftag="Bulleted text"> <paraline> <xref srctext="55167: 1st Section: How Does XXX Work?"><render charformat="Bold"> How Does XXX Work?</render></xref> </paraline> </para> <para pgftag=bChapterb> <paraline>Next chapter</paraline> </para> </textflow> The idea is, quite obviously, grouping the relevant list items, so youbd end up (ideally!) with something like e.g.: <book> <chapter> <title>Introduction</title> <p>This chapter explains...</p> <ul> <li>Display the online help as follows:</li> <ul> <li>To view the help for a panel, press the help (PF1) key.</li> <li>To view the help for an input field or select a parameter from a pop-up window, press PF1.</li> </ul> <note> If you do not specify a required parameter, or enter an incorrect one, XXXX will prompt you for the correct information.</note> <li>Check relevant sections of <em>XXXX</em>.</li> <li>Visit our web site to get ...</li> </ul> <p> The topics covered are:</p> <ul> <li><b>What is XXX?</b></li> <li><b>How Does XXX Work?</b></li> </ul> </chapter> <chapter> <title>Next chapter</title> </chapter> </book> As you can see, the source is a completely flat, linear sequence from which I have to establish every kind of structure. Therefore, I use something like <xsl:template match=btextflowb> <book><xsl:apply-templates/></book> </xsl:template> <xsl:template match=bpara[@pgftag=bChapterb]b> <xsl:variable name="chapter-id" select="generate-id()"/> <chapter> <title><xsl:apply-templates/></title> <xsl:apply-templates select="following-sibling::*[not(self::*[@pgftag='Chapter'])] [generate-id(preceding-sibling::para[@pgftag='Chapter'][1]) = $chapter-id]"/> </chapter> </xsl:template> <xsl:template match=bpara[@pgftag=bBulleted textb]b>... That is, I canbt imagine having a single template matching textflow in which I apply <xsl:for-each-group> for all kinds of different paras. Instead, I use Muenchian grouping (yep, starting with XSL 1.0, but now I use 2.0), but ran into serious recursion trouble when fiddling with nested chapter and list structures. The other principal problem is how to decide when a structure has ended, because all elements are on the same sibling axis. Now, a chapter ends, when another <para pgftag=bChapterb> or some <para pgftag=bAppendixb> appears. But there is no way to decide when the first bulleted list in the example really ends, since the list items may include other elements such as notes or nested lists. You could only use criteria such as bThis list has ended, when the next paragraph is e.g. <para @pgftag=bBody textb> or <para @pgftag=bChapterb> appearsb. Now, if anyone could point me in the right direction, Ibd be very grateful, since itbs bugging me for some time now. And, please apologize the length... Thank you, Frank Software AG b Sitz/Registered office: UhlandstraCe 12, 64297 Darmstadt, Germany b Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Merging common tags of 2 , Martin Honnen martin | Thread | Re: [xsl] Problems grouping nested , David Rudel fwqhgads |
Re: [xsl] Merging common tags of 2 , Martin Honnen martin | Date | Re: [xsl] Problems grouping nested , David Rudel fwqhgads |
Month |