Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XHTML changing

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 9/1/2007 9:17:00 AM

"Philipp Kraus" <philipp.kraus@f...> wrote in message 
news:fba6ns$tp4$1@o......
> Hello,
>
> I hope my question isn't off topic.
> I have a XHTML file (offline webpage) and now I change some HTML 
> struktures with a XSLT.
> I create my XSLT file and in my first step I will copy all HTML tags and 
> one tag should be cleared.
> I have build my XSLT with a editor like this way:
>
> <xsl:template match="sem">
> <xsl:text>\section{</xsl:text>
> <xsl:value-of select="@value"/>
> <xsl:text>}</xsl:text>
> <xsl:apply-templates />
> </xsl:template>
> <xsl:template match="name">
> <xsl:text>\subsection{</xsl:text>
> <xsl:value-of select="@value"/>
> <xsl:text>}</xsl:text>
> <xsl:apply-templates />
> </xsl:template>
>
> In my HTML Struktur I have this path: html/body/div (@aussen) / hr (@hide) 
> / div (@page) / hr (@hide) / div (@navi) (all @ are attributes). It's also 
> a typo3 strukture. I would like to clear everything on the node "div 
> (@navi)" and all childs down of the node. All other HTML Tags should be 
> copy in a new HTML.
> Is this the right way?
>
> <xsl:template match="path_to_div_navi">
> checking attribute named "navi"
> no -> <xsl:apply-templates />
> yes -> nothing
> </xsl:template>
> <xsl:template match="*">
> how I copy a node with full data?
> </xsl:template>
>
> Thanks a lot
>
> Phil
>
>
Phil

Two things:
1) If your file is XHTML then you'll need to include the XHTML namespace 
declaration and your XPath should include the associated prefix: 
xhtml:html/xhtml:body/... etc.
2) If you just intend to copy all but a specific part then the standard 
practice is to use the identity transform with template overrides for 
elements that you don't need. For example to copy all but div elements with 
a class attribute of hide and their children then use:

<!-- The Identity Transformation -->
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Whenever you find any node or any attribute -->
  <xsl:template match="node()|@*">
    <!-- Copy the current node -->
    <xsl:copy>
      <!-- Including any attributes it has and any child nodes -->
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- Overrides here -->
  <xsl:template match="div[@class='hide']/>
</xsl:stylesheet>

(I've not included the namespace stuff here, check 
http://www.dpawson.co.uk/xsl/sect2/N5536.html numbers 13 and 23 for more 
info.)

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name





transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent