xsl-list
[Top] [All Lists]

RE: [xsl] not working as expected

2007-05-14 02:12:44
I need to generate a XHTML page similar to the one presented 
below. (I know it is wrong use of CDATA but I was unable 
generate some tages that are presented in the required xhtml page)

Well, your first step is to stop thinking about tags, and start thinking
about nodes. You're attacking this at far too low a level. Using the text
output method when you want to generate XHTML is making life far too
difficult.

What part of the output are you having difficulty with?

* your output contains <s:div> where s is an undeclared namespace prefix.
You're not going to be able to generate that in a conventional result tree,
but why would you want to, given that it is invalid XHTML?

* your output contains "<br />" with the extra space before the "/" as
needed by browsers that are treating your XHTML as if it was HTML. Some XSLT
processors give you an XHTML output method that does this for you. But why
do you need it? If the browser doesn't understand "real" XHTML, and needs it
to be formatted as if it were HTML, then why not simply generate HTML in the
first place? Alternatively, another workaround that's just as effective in
getting the output accepted by an HTML browser, and which distorts your code
far less, is to generate <br dummy="dummy"/>

* your output contains br and b elements (sorry, tags) in the wrong order.
That's simply because you've done:

  <xsl:apply-templates select="BREAK"/>
  <xsl:apply-templates select="B"/>

which processes all the BREAK elements before starting on the B elements.
You can fix that simply by writing

<xsl:apply-templates select="BREAK|B"/>

Michael Kay
http://www.saxonica.com/



/*
---- xhtml to be generated
<s:div StyleClass ="block_c_1"><p>
<b>Welcome Zeeshan!</b><br /> <br />
<b>DOB: </b>August 20 1979 <br /> <br /> <b>We are committed 
to provide an enlightening and safe environment to all 
convention attendees.<br /> <br /></b>
<b>Site: Saroba Garden Lahore </b><br /> <br /> </p> </s:div>

--- xhtml generated
<s:div StyleClass ="block_c_1"><p><br /> <br /> <br /> <br /> 
<br /> <br /> <br /> <br /> <b>Welcome Zeeshan!</b>
<b>DOB: </b>
<b>We are committed to provide an enlightening and safe 
environment to all convention attendees.</b>
<b>Site: Saroba Garden Lahore </b></p>
</s:div>
--- xml used
<DIVS StyleClass="block_c_1" > <PG>
<B>Welcome Zeeshan!</B>
<BREAK /><BREAK />
<B>DOB: </B>August 20 1979<BREAK /><BREAK /> <B>We are 
committed to provide an enlightening and safe environment to 
all convention attendees.</B><BREAK /><BREAK />
<B>Site: Saroba Garden Lahore </B> <BREAK /><BREAK /> </PG> </DIVS>
------- xslt (I know it is wrong use of CDATA but I was 
unable generate the tages that are presented in the req xhtml 
page) <xsl:output method="text"/> <xsl:strip-space elements="*"/>

<xsl:template match="DIVS">
<xsl:text><![CDATA[
<s:div ]]></xsl:text>
 <xsl:if test="@StyleClass"><xsl:text>StyleClass 
="</xsl:text>  <xsl:value-of select="@StyleClass" 
/><xsl:text><![CDATA[">]]></xsl:text>
 </xsl:if>
 <xsl:apply-templates select="PG"/>
<xsl:text><![CDATA[
</s:div>]]></xsl:text></xsl:template>

<xsl:template match="PG"> <xsl:text><![CDATA[<p>]]></xsl:text>
<xsl:apply-templates select="BREAK"/>
<xsl:apply-templates select="B"/>
<xsl:text><![CDATA[</p>]]></xsl:text></xsl:template>

<xsl:template match="BREAK"><xsl:text><![CDATA[<br
/> ]]></xsl:text></xsl:template>

<xsl:template match="B"> <xsl:text><![CDATA[ 
<b>]]></xsl:text> <xsl:value-of select="."/> 
<xsl:text><![CDATA[</b>]]></xsl:text></xsl:template>
*/ 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>