XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XSLT Stylesheet Exclude Parental Search Results?

>

completely untested, but with XSL 2 you could do:

<xsl:template match="/">
   <xsl:apply-templates select="//ns:div[@id='as1']/ns:p"/>
</xsl:template>

<xsl:template match="ns:p">
   <xsl:element name="{normalize-space(ns:strong)}">
     <xsl:value-of select="(ns:a, normalize-space(text() 
[not(position()=1)]))[1]"/>
   </xsl:element>
</xsl:template>


> I would like to extract only the content of the following mixed XML  
> document converted from XHTML format:
>
>
> <?xml version="1.0" encoding="UTF-8" ?>
>
> <!DOCTYPE html (View Source for full doctype...)>
>
> - <html xmlns="http://www.w3.org/1999/xhtml"; xmlns:html="http://www.w3.org/1999/xhtml 
> ">
>
> - <head>
>
> - <body
>
> .......
>
> - ><div id="container">
>
> + <div id="header">
>
> <div id="postmark" />
>
> - <div id="content">
>
> + <div id="as1">
>
> .......
>
> <h1>Employee Detail</h1>
>
> - <p>
>
> <strong>Firstname:</strong>
>
> <a >John</a>
>
> </p>
>
> - <p>
>
> <strong>Surname:</strong>
>
> <a >Smith</a>
>
> </p>
>
> - <p>
>
> <strong>Date of birth:</strong>
>
> 12/01/1932
>
> </p>
>
> - <p>
>
> <strong>Sex:</strong>
>
> M
>
> </p>
>
> - <p>
>
> <strong>Interest:</strong>
>
> <br />
>
> Tennis
>
> <br />
>
> Movie
>
> <br />
>
> .....
>
>
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <xsl:stylesheet version="1.0"
>
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>
> xmlns:ns="http://www.w3.org/1999/xhtml";
>
> exclude-result-prefixes="ns">
>
>
> <xsl:template match="/">
>
> <area>
>
> <xsl:if test="/ns:html/ns:body/ns:div[@id='content']/ns:p/ns:strong">
>
> <xsl:choose>
>
> <xsl:when test="contains(.,'Firstname:')">
>
> <firstname><xsl:value-of select="."/></firstname>
>
> </xsl:when>
>
> <xsl:otherwise>
>
> <firstname>Unknown</firstname>
>
> </xsl:otherwise>
>
> </xsl:choose>
>
> </xsl:if>
>
> </area>
>
> </xsl:template>
>
>
> </xsl:stylesheet>
>
>
> Not only did XSLT returned all the correct employee data but also  
> included a lot of irrelvant data from the parental nodes as well. In  
> other word, it return the contents from ns:html, ns:body,  
> ns:div[@id='content'], ns:p, ns:strong which I don't want. Is there  
> a way to prevent (exclude/mask) all these ancestral data from being  
> included and only pick up the data in /ns:html/ns:body/ 
> ns:div[@id='content']/ns:p/ns:strong cleanly?
>
>
> Many thanks,
>
> Jack
>
>
> Stay connected to the people that matter most with a smarter inbox.  
> Take a look.



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS