• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

XSLT Stylesheet Exclude Parental results?

 
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I would like to extract only the content of the following mixed XML document converted from XHTML format:


XSLT not only returned all the correct employee data but also include a lot more irrelvant data from the parent nodes as well. In other word, it also 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
 
Sheriff
Posts: 28325
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what you are doing:

1. You match on the root, which sets the context node to the root.

2. You test (via xsl:if) if the root contains a /ns:html/ns:body/ns:div[@id='content']/ns:p/ns:strong element (which it does).

3. You test (via xsl:when) whether the text content of the root contains 'Firstname:' (which it does).

4. You output (via xsl:value-of) the text content of the root.

Note that all those operations act on the context node. So what you want to do is to change the context node to whatever it is you want to copy. There are two ways to change the context node in XSLT. One is xsl:for-each and the other is xsl:template match="x".
 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thank you for responding to my call for assistance time and time again.

Any further suggestion would be appreciated.

Thanks again,

Jack
 
Paul Clapham
Sheriff
Posts: 28325
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's an error message which says that xsl:for-each doesn't have a "test" attribute, but you provided one. And there's an error message which says that xsl:for-each requires a "select" attribute, but you didn't provide one. Does this not suggest a fairly obvious course of action? If it doesn't, you could still look up the syntax of the xsl:for-each element, couldn't you?
 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

I managed to locate only those nodes in "/ns:html/ns:body/ns:div[@id='content']/ns:p/ns:strong" by using xsl:if followed by the xsl:choose nested inside for each element. This will ensure that XSLT will not find anything above this node.

Jack
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic