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

[xslt] Problem changing a contained element to a follo

Subject: [xslt] Problem changing a contained element to a following element
From: <email@xxxxxxxx>
Date: Fri, 27 Jun 2003 14:23:34 -0500
contain xslt
Hi,

I didn't think of myself as an XSLT newbie, but this problem sure is making
me feel like one.

All I want to do is to change:

<p>some text
    <ul>
      <li><p>item1</p>
      <li><p>item1</p>
   </ul>
</p>

to:

<p>some text</p>
<ul>
   <li><p>item1</p>
   <li><p>item1</p>
</ul>

I don't want <p> to contain <ul>.  The <p> must end before the <ul> begins.

I run the following with Xalan Java 2.2.0:

<?xml version="1.0"?>

<xsl:transform
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xalan="http://xml.apache.org/xslt"
		version="1.0">

<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="contents">

	<contents-corrected>
		<xsl:apply-templates/>
	</contents-corrected>

</xsl:template>

<xsl:template match="p">

	<p-unchanged>
		<xsl:apply-templates/>
	</p-unchanged>

</xsl:template>


<!--
*
*	A paragraph that contains an unordered list should be changed into a
paragraph
*	*followed* by an unordered list.
*
-->

<xsl:template match="p[child::ul]">

	<p-corrected>
		<xsl:apply-templates select="node()[not(ul)]"/>
	</p-corrected>

	<xsl:apply-templates select="ul"/>

</xsl:template>


<xsl:template match="ul | li">

	<xsl:copy-of select="."/>

</xsl:template>

</xsl:transform>

With this input XML:

<?xml version="1.0" encoding="UTF-8"?>
<snippet>
	<contents>
		<p>The likelihood of achieving an accumulation goal is affected by these
factors&#58;
			<ul>
				<li>
					<p>Inflation of goal&#45;related costs</p>
				</li>
				<li>
					<p>The original amount invested</p>
				</li>
				<li>
					<p>The rate of return on invested assets</p>
				</li>
			</ul>
		</p>
		<p>Consequently, a calculation showing the need for additional resources
to achieve your accumulation goal will be directly affected by changes in
any of these factors.
		</p>
	</contents>
</snippet>

And I get this result:

<?xml version="1.0" encoding="UTF-8"?>

	<contents-corrected>
		<p-corrected>The likelihood of achieving an accumulation goal is affected
by these factors:
			<ul>
				<li>
					<p>Inflation of goal-related costs</p>
				</li>
				<li>
					<p>The original amount invested</p>
				</li>
				<li>
					<p>The rate of return on invested assets</p>
				</li>
			</ul>
		</p-corrected><ul>
				<li>
					<p>Inflation of goal-related costs</p>
				</li>
				<li>
					<p>The original amount invested</p>
				</li>
				<li>
					<p>The rate of return on invested assets</p>
				</li>
			</ul>
		<p-unchanged>Consequently, a calculation showing the need for additional
resources to achieve your accumulation goal will be directly affected by
changes in any of these factors.
		</p-unchanged>
	</contents-corrected>


I am confounded as to why the <ul> comes out twice due to this template:


<xsl:template match="p[child::ul]">

	<p-corrected>
		<xsl:apply-templates select="node()[not(ul)]"/>
	</p-corrected>

	<xsl:apply-templates select="ul"/>

</xsl:template>

I'm hoping I'm missing something obvious and that someone here can find it
easily.  Thanks!

. . . Phil





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.