Hi,
I am trying to group with a key using XSLT 1.0. Here is my input:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="local.css" type="text/css" />
<title>Creating a Group</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<p class="listintro">To create a group of applications to manage the group
using a common policy:</p>
<p class="listitem1">1. Open the Desktop to the Application Manager.</p>
<p class="listitem2">2. From the service menu, select New Group...</p>
<p class="figure"> </p>
<p class="caption"><b>Creating a Group</b></p>
<p class="listitem2">3. The Group properties window opens.</p>
<p class="figure"> </p>
<p class="caption"><b>Creating a Group</b></p>
<p class="listitem2">4. Enter a name in Group Name.</p>
<p class="listitem2">5. Select an application by clicking Add All.</p>
<p class="listitem2">6. When you are finished, click Save.</p>
</body>
</html>
I want to group items like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="local.css" type="text/css" />
<title>Creating a Group</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<p class="listintro">To create a group of applications to manage the group
using a common policy:</p>
<ol start="1">
<li>1. Open the Desktop to the Application Manager.</li>
<li>2. From the service menu, select New Group...</li>
</ol>
<p class="figure"> </p>
<p class="caption"><b>Creating a Group</b></p>
<ol start="3">
<li>3. The Group properties window opens.</li>
</ol>
<p class="figure"> </p>
<p class="caption"><b>Creating a Group</b></p>
<ol start="4">
<li>4. Enter a name in Group Name.</p>
<li>5. Select an application by clicking Add All.</li>
<li>6. When you are finished, click Save.</li>
</ol>
</body>
</html>
Here is my stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml xsl"
version="1.0">
<xsl:key name="orderedlist" match="xhtml:p[@class='listitem1' or
@class='listitem2'][preceding-sibling::*[1][self::xhtml:p[@class='listitem1'
or @class='listitem2']]]"
use="generate-id(preceding-sibling::xhtml:p[@class='listitem1' or
@class='listitem2'][not(preceding-sibling::*[1][self::xhtml:p[@class='listit
em1' or @class='listitem2']])])" />
<!-- IdentityTransform -->
<xsl:template match="/ | @* | node()" name="identity">
<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>
</xsl:template>
<xsl:template match="xhtml:p[@class='listitem1' or
@class='listitem2'][not(preceding-sibling::*[1][self::xhtml:p[@class='listit
em1' or @class='listitem2']])]">
<ol start="{substring-before(node(),'.')}">
<li><xsl:copy-of select="node()"/></li>
<xsl:apply-templates mode="copy" select="key('orderedlist',
generate-id())"/>
</ol>
</xsl:template>
<xsl:template match="xhtml:p[@class='listitem1' or
@class='listitem2'][preceding-sibling::*[1][self::xhtml:p[@class='listitem1'
or @class='listitem2']]]"/>
<xsl:template match="xhtml:p[@class='listitem1' or @class='listitem2']"
mode="copy">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>
The wrinkle here is that in the original XML, the first list item has an
attribute of "listitem1" while all the rest have "listitem2". I am missing
something vital in my understanding, because I am getting this:
<?xml version="1.0" encoding="UTF-8"?><html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="local.css" type="text/css"/>
<title>Creating a Group</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p class="listintro">To create a group of applications to manage the group
using a common policy:</p>
<ol start="1"><li>1. Open the Desktop to the Application
Manager.</li><li>2. From the service menu, select New Group...</li><li>5.
Select an application by clicking Add All.</li><li>6. When you are finished,
click Save.</li></ol>
<p class="figure"> </p>
<p class="caption"><b>Creating a Group</b></p>
<ol start="3"><li>3. The Group properties window opens.</li></ol>
<p class="figure"> </p>
<p class="caption"><b>Creating a Group</b></p>
<ol start="4"><li>4. Enter a name in Group Name.</li></ol>
</body>
</html>
Thanks in advance for any help you can provide. I really want to understand
this.
Rick
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--