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

RE: RE: How to strip out a pair of <p> tag from xml d

Subject: RE: RE: How to strip out a pair of <p> tag from xml data before puttingout on an html page using XSL?
From: cknell@xxxxxxxxxx
Date: Tue, 03 Feb 2004 11:50:33 -0500
xsl strip tags
If you don't know whether your input will have <p> elements, but you want to be sure that if it does, you want only the content to be copied to the output, you have to create a template to do it. So, in the case of your <p> element you will want a template like this:

<xsl:template match="p">
  <xsl:value-of select="." />
</xsl:template>

In your input XML you want to process each <FAQs> element to extract the <Question> and <Answer> child elements, but if either of these have one or more <p> child elements, you want only the text of the <p> elements in the output, if I understand your requirements.

Furthermore, your input may have unordered list <ul> elements that you want to copy. Your use of <xsl:for-each> leads me to believe that you are relatively new to XSLT and that your have experience with other kinds of programming. You will want to abandon that mindset and embrace the XSLT way of doing things. Write a set of templates to produce your output instead of trying to get everthing in one comprehensive template as you have now.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />

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

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

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

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

<xsl:template match="FAQs">
  <p><table>
  <tr><td><a href="#{generate-id(Question)}"><span id="questionlist"><strong><xsl:copy-of select="normalize-space(Question)" /></strong></span></a></td></tr>
  </table></p><br/>
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="Question">
  <a name="#{generate-id(.)}">
  <span id="question">
    <strong>Q. <xsl:value-of select="normalize-space(.)" /></strong>
  </span></a><br />
</xsl:template>

<xsl:template match="Answer">
  <strong>A. </strong><xsl:value-of select="normalize-space(.)" />
  <xsl:apply-templates />
  <br/><br/>
</xsl:template>

<xsl:template match="p">
  <xsl:value-of select="normalize-space(.)" />
</xsl:template>

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

<xsl:template match="li[p]">
  <li><xsl:apply-templates /></li>
</xsl:template>

<xsl:template match="li[not(p)]">
  <li><xsl:value-of select="normalize-space(.)" /></li>
</xsl:template>

<xsl:template match="Content_Owner" />
<xsl:template match="Content_Owner_Email" />
<xsl:template match="Keywords" />
<xsl:template match="Page_Title" />
<xsl:template match="Page_Text" />

</xsl:stylesheet>

-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Govil, Anoop (Contractor) <Anoop.Govil@xxxxxxxxxxxxxxxx>
Sent:     Tue, 3 Feb 2004 10:25:02 -0500
To:       "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  RE:  How to strip out a pair of  <p> tag from xml data before  puttingout on an html page using XSL?

Thanks for your reply Charles. Actually, these come in as a formatted html
blurb to me so I just put them out as it is inputed by the user. It may or
may not contain formatting so that was my problem as I can not expect any of
those elements to be always there to build them by hand. Could you elaborate
on your suggestion by hopefully an example? Thanks.

Anoop

-----Original Message-----
From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx]
Sent: Tuesday, February 03, 2004 10:07 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  How to strip out a pair of <p> tag from xml data
before puttingout on an html page using XSL?


You don't get rid of them by striping them out. You get rid of them by not
putting them in. It looks like they are getting in by using xsl:copy-of to
take them from the source and put them in the output. Try building these
elements by hand.
-- 
Charles Knell
cknell@xxxxxxxxxx - email



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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