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

Re: Matching or selecting template problem

Subject: Re: Matching or selecting template problem
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Thu, 15 Jan 2009 17:51:17 +0200
Re:  Matching or selecting template problem
Hi Charles,

You can approach this with the recursive identity transformation and just add a rule for processing conbody

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


<xsl:template match="conbody"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="section"/> <section> <xsl:apply-templates select="*[not(self::section)]"/> </section> </xsl:copy> </xsl:template>

or, if you want to keep also some of the indenting text:

<xsl:template match="conbody">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="section|text()[not(preceding-sibling::*) or preceding-sibling::*[1][self::section]]"/>
<section>
<xsl:apply-templates select="*[not(self::section)]|text()[not(following-sibling::section)]"/>
</section>
</xsl:copy>
</xsl:template>



Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com

Charles Flanders wrote:
There are some advanced aspects of XSLT that I just don't seem to "get." I'm really struggling with what some of you may consider a simple problem. I can seem to find a way to match part of the following instance. I've tested the following XPath statements with Oxygen and get the results I want. Somehow I can't seem to translate that into a template match.

Wendell, you've been a great help to my previous questions, I hope you're not disappointed in me as a former student. Unfortunately, a full year has passed since a requirement has developed for me to put the XSLT coursework into a real world exercise.

My problem: I need to match all the following sibling elements of the last <section> (in this case two <p> element and a <ul>) and create a new sibling <section> with the current following siblings as children of the new <section>.

I have tried:

conbody/section[last()]/following-sibling::* (XPath returns the correct result, but not valid as a template match)

<xsl:template match="//conbody/section[last()]/p"/> Again, the XPath test gives me the expected result, but doesn't seem to match in a tempate
<xsl:template match="//conbody/section[last()]/ul"/> Same as previous.


I think I can create a template to match the following siblings of the last <section>, I can use a For Each to create the new section? Am I on the right track ? I'm unclear as to how to create new high level elements in which I need to nest EXISTING elements.

I appreciate any solutions, but I would also like to understand the parts of this I seem to "get."

Current content:*
*
<?xml version="1.0" encoding="UTF-8"?>
<concept  class="- topic/topic concept/concept">
   <title>TITLE</title>
   <prolog class="- topic/prolog "/>
   <conbody class="- topic/body concept/conbody">
       <section><title>TITLE</title></section>
       <section><title>TITLE</title></section>
       <section><title>TITLE</title></section>
       <p>TEXT</p>
       <p>TEXT</p>
       <ul>
           <li>
               <p>
                   TEXT
               </p>
           </li>
           <li>
               <p>
                   <xref/>
               </p>
           </li>
       </ul>
   </conbody>
</concept>

Desired Result:

<?xml version="1.0" encoding="UTF-8"?>
<concept class="- topic/topic concept/concept">
   <title>TITLE</title>
   <prolog class="- topic/prolog "/>
   <conbody class="- topic/body concept/conbody">
       <section><title>TITLE</title></section>
       <section><title>TITLE</title></section>
       <section><title>TITLE</title></section>
      <section>
       <p>TEXT</p>
       <p>TEXT</p>
       <ul>
           <li>
               <p>
                   TEXT
               </p>
           </li>
           <li>
               <p>
                   <xref/>
               </p>
           </li>
       </ul>
      </section>
   </conbody>
</concept>

Charles Flanders
cflanders@xxxxxxxxxx

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-2011 All Rights Reserved.