[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] remove certain elements but keep children


Subject: Re: [xsl] remove certain elements but keep children
From: Anton Triest <anton@xxxxxxxx>
Date: Mon, 04 Oct 2004 20:41:45 +0200

Hi Ben,

There are two (maybe more) slightly different ways to do an identity transform.
You can do


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

the result is the same (a deep copy of all nodes and attributes).

Now if you look carefully at your identity template, you'll see it's a bit of a mix of both ways...
Fix this and it should work


Cheers,
Anton


Ben Munat wrote:


Hmmm, seems my enthusiasm was premature... can't get any of the suggestions to work. I must be applying it wrong... or maybe my little sample doc in my first email was misleading. Here's a more exact file I'm working with:

-------input file:--------------

<?xml version="1.0" encoding="UTF-8"?>
<output type="root">
   <output type="static" id="3014deec-86c8-b69f-8c21-7420ac545008">
      <div class="header">
         <p class="tagline">My Site is great</p>
         <h1 class="logo">MYSITE</h1>
      </div>
   </output>

   <output type="static">
      <div class="page-body">
         <output type="static">
            <div class="sidebar">
               <output type="static" >
                  <div class="navbar">
                     <h2 class="navbar-title">The Site</h2>
                     <ul class="navbar-links">
                        <li>
                               <a class="navbar" href="/Focus/">
                    Focus
                </a>
                        </li>

                        <li>
                            <a class="navbar" href="/History/">
                    History
                </a>
                        </li>

                        <li>
                           <a class="navbar" href="/Activities/">
                    Activities
                </a>
                        </li>
                     </ul>
                  </div>
               </output>

               <output type="login">
                  <div class="sidebar-box">
                     <form class="site-login"
            action="http://localhost:8080/" method="post">
                        <h2 class="sidebar-title">Log In</h2>

                        <p class="sidebar-text">
                           <label for="user-name">Username:</label>
                           <input id="user-name" name="user_name"
                type="text" size="16" />
                           <br />
                           <label for="user-password">Password:</label>
                           <input id="user-password"
                name="user_password"
                type="password" size="16" />
                           <input id="user-login" name="user_login"
                type="submit" value="log in" />
                        </p>

<p class="sidebar-link">
<a class="sidebar" href="/Register/">Register</a>
<br />
<a class="sidebar"
href="/ResetPassword/">
Reset Password</a>
</p>
</form>
</div>
</output>
</div>
</output>


         <output type="static" >
            <h3 class="article-title">What is the BEACONS Project?</h3>

            <div class="article-body">
            <p>Lobore et dolore nagna aliquam erat volupat.
            At enim ad minimin veniami
            quis nostrud exercitation lorem ipsum dolor sit
            amet, consectetur adips cing
            elit, diam nonnumy eiusmod tempor incidunt ut
            ullamcorper suscripit laboris nisi
            ut alquip exea commodo consequat, consectetur
            adips cing elit. Ullamcorper
            suscripit laboris nisi ut alquip exea commodo
            consequat, consectetur adips
            cing elit.</p>

<p>Lobore et dolore nagna aliquam erat volupat.
At enim ad minimin veniami
quis nostrud exercitation lorem ipsum dolor sit amet, consectetur adips cing
elit, diam nonnumy eiusmod tempor incidunt ut
ullamcorper suscripit laboris nisi
ut alquip exea commodo consequat, consectetur
adips cing elit. Ullamcorper
suscripit laboris nisi ut alquip exea commodo
consequat, consectetur adips
cing elit.</p>
</div>
</output>
</div>
</output>


   <output type="static" id="eb2260c3-5ca5-fd34-6b28-64613dc1b67a">
      <p class="global-links">
         <a class="global" href="/ContactUs/"
        title="Contact the webmaster">ContactUs</a>

         <a class="global" href="/PrivacyPolicy/"
        title="How we handle your private data">
        PrivacyPolicy</a>

         <a class="global" href="/TermsOfUse/"
        title="Terms and conditions for using this site">
        TermsofUse</a>
      </p>
   </output>

   <output type="static" id="1ac7a8b0-5665-3aaa-5c3c-1ad58a630ee2">
      <div class="code-links">
         <a href="http://validator.w3.org/" title="Valid XHTML 1.1">
        XHTML</a>

         <a href="http://jigsaw.w3.org/css-validator/"
        title="Valid CSS 2">CSS</a>

         <a href="http://www.w3.org/WAI/WCAG1AA-Conformance"
        title="Accessible to AA WCAG 1.0">WCAGAA</a>
      </div>
   </output>
</output>

-------------------------------------

I'm trying to simply remove the opening an closing "output" tags. Here's my latest attempt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no"/>


<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
</head>
<body>
<xsl:apply-templates select="*"/>
</body>
</html>


</xsl:template>

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

<xsl:template match="output">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>


Although I've tried several variations in the "match" and "select" attributes. I always seem to get not quite all the html elements or I get multilple copies of stuff.

What am I doing wrong?

Thanks,

Ben


Current Thread
Keywords