[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Finding an untagged ordered list

Subject: Re: Finding an untagged ordered list
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Wed, 14 Jan 2009 12:51:37 +0100
Re:  Finding an untagged ordered list
I love to play with Kernow's XSLT Playground feature and your case way
well prepared for that.

With the help of xsl:for-each-group and regular expressions your case
can be solved. I did not try to exclude the possibly  last P from the
OL and I did not check for the alphabetical order. You would have to
specify more clearly what should happen, but look at this:

<xsl:template match="root">
    <xsl:for-each-group select="*"
      group-adjacent="if (self::P and
      (self::P[matches(., '^[A-Z][.]')] or
      preceding-sibling::P[matches(., '^[A-Z][.]')]))
      then 0 else position()">
        <xsl:when test="current-grouping-key() = 0">
            <xsl:for-each-group select="current-group()"
              group-starting-with="P[matches(., '^[A-Z][.]')]">
                <xsl:when test="./self::P[matches(., '^[A-Z][.]')]">
                    <xsl:apply-templates select="current-group()"
                  <xsl:apply-templates select="current-group()"/>
          <xsl:apply-templates select="."/>

<xsl:template match="node()" mode="join">
  <xsl:apply-templates select="@*|node()"/>
  <xsl:value-of select="' '"/>

<xsl:template match="@*|node()">
    <xsl:apply-templates select="@*|node()"/>

It creates

   <P>List Heading</P>
      <LI>A. One big sentence incorrectly placed in P tags </LI>
      <LI>B. Another long sentence spanning P tags. </LI>
      <LI>C. This should really be one long list item that spans
randomly. Hopefully I am some unrelated text. </LI>

Good luck!

- Michael

Am 13.01.2009 um 23:45 schrieb Graeme Kidd:

Hi everyone,
I am using XSLT 2.0 and I have three questions about an ordered list
in this format:
  <P>List Heading</P>
  <P>A. One big</P>
  <P>sentence incorrectly</P>
  <P>placed in P tags</P>
  <P>B. Another long</P>
  <P>sentence spanning P tags.</P>
  <P>C. This should really</P>
  <P>be one</P>
  <P>list item</P>
  <P>that spans randomly.</P>
  <P>Hopefully I am some unrelated text.</P>

Which I want converted to this format:
  <P>List Heading</P>
      <LI>One big sentence incorrectly placed in P tags.</LI>
      <LI>Another long sentence spanning P tags.</LI>
      <LI>This should really be one long list item that spans
  <P>Hopefully I am some unrelated text.</P>

Due to the original XML file being rather bad the list may not start
at A. Before I have been able to catch a numbered list just by
checking if the P tag starts with a number and its preceding sibling
does not, then when I am inside the list check if the next P tag
starts with a number a well. This list is different though.

1) I imagine you can check if the P tags starts with a letter by
doing something like this:
P[starts-with(translate(., 'vUppercaseChars_CONST',
'vUppercaseAChar_CONST'), 'A')]
How would you then check it begins with letter followed by a dot?

2) Is it possible to find a letter followed by a dot then check if
the next P node starts with the next letter of the alphabet followed
by a dot?

3) Is it possible to check if the next 10 P tags contain the next
letter of the alphabet plus a dot. Previously I have been able to
pick up lists no problem when they had a predictable pattern but
this one doesn't. I can only assume that the list ends after about
10 P tags or it finds a character in a previous position in the
alphabet or it hits some other tag that is not a P tag. I would end
the list item at the first full stop it found after the last P tag
that started with character plus a dot. Is something like this
possible in XSLT and if so how?

Thanks for your time,

-- _______________________________________________________________ Michael M|ller-Hillebrand: Dokumentation Technology Adobe Certified Expert, FrameMaker Consulting and Training, FrameScript, XML/XSL, Unicode Blog [de]: http://cap-studio.de/

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.