Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT Help

 
Hari Shankar Gentyala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following XML file.

<root>
<PDAT></PDAT>
<INS-S DATE="20011023" ID="INS-S-00001"/>
CROSS-
<PDAT>REFERENCE TO RELATED APPLICATION </PDAT>
<INS-E/>
<ITALIC>
<PDAT>
asldfsaklalsasdflkjsadf
</PDAT>
</ITALIC>
</root>

This is just an example of my requirement.My output should be something of this form.
My output should display a special font like <font color="blue> when the text is in between the elements <INS-S/> and <INS-E/>.
The problem is I am unable to track the elements which may come in between these two elements.

Can someone help me out with this problem.

Thanks in advance,
Hari
[ October 17, 2003: Message edited by: Hari Shankar Gentyala ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain what are you currently doing so that we might be able to point out where you're going wrong?
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got this working, but very awkwardly. Hope it can help you start on it.
<xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="alltextnodes" select="/root/text() | /root/*"/>
<xsl:for-each select="$alltextnodes">
<xsl:if test="local-name() = 'INS-S'">
<xsl:variable name="start" select="position()"/>
<xsl:for-each select="$alltextnodes">
<xsl:if test="local-name() = 'INS-E'">
<xsl:variable name="end" select="position()"/>
<xsl:for-each select="$alltextnodes">
<xsl:if test="position() > $start and position() < $end ">
<font color="red"><xsl:value-of select="."/></font>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
 
Hari Shankar Gentyala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony for your help,
Here is my actual XML file.
<RELAPP>
<BTEXT>
<H LVL="1">
<STEXT>
<PDAT>
<INS-S DATE="20011023" ID="INS-S-00001"/>
CROSS-
</PDAT>
<HIL>
<ITALIC>
<PDAT>REFERENCE TO RELATED APPLICATION
<INS-E ID="INS-S-00001"/>
</PDAT>
</ITALIC>
</HIL>
</STEXT>
</H>
<PARA ID="P-00002" LVL="0">
<PTEXT>
<PDAT>This
<INS-S DATE="20011023" ID="INS-S-00002"/>
is a continuation of application Ser. No.
</PDAT>
<HIL>
<BOLD>
<PDAT>08</PDAT>
</BOLD>
</HIL>
<PDAT>, now abandoned, which
<INS-E ID="INS-S-00002"/>
is a continuation of co-pending application Ser. No. 07/160,630 filed on 26 Feb. 1988 now abandoned.
</PDAT>
</PTEXT>
</PARA>
</BTEXT>
</RELAPP>

And the output should be something in this form:
<font color="red">
CROSS-REFERENCE TO RELATED APPLICATION</font>This <font color="red">is a continuation of application Ser. No.08, now abandoned, which </font>
is a continuation of co-pending application Ser. No. 07/160,630 filed on 26 Feb. 1988 now abandoned.
i.e after the element INS-S starts, the font should change to red and this font should end with the element INS-E.The remaining text should display same.

Can you help me with this requirement.
thanks,
Hari
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, it gets simpler like this.

Here is the output from my transformer(xalan):
<font color="red"> CROSS- REFERENCE TO RELATED APPLICATION </font> This <font color="red"> is a continuation of application Ser. No. 08, now abandoned, which </font> is a continuation of co-pending application Ser. No. 07/160,630 filed on 26 Feb. 1988 now abandoned.

Regards,
 
Hari Shankar Gentyala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
Thanks for your reply but my XSLT processor(Xalan) is reporting error as this is not a well formed document.

It is saying as if the <font> is to be closed.

Thanks,
Hari
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can encapsulate the <font> element into a <![CDATA[...]]> block.
EDIT: I noticed a syntax error and corrected it
[ October 23, 2003: Message edited by: Lasse Koskela ]
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse is right. Or, you can use entities like & l t ; (remove the space) to replace <
Rgds,
 
Hari Shankar Gentyala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony and Lasse,
I tried that way.It is printing <font > but not changing the color of my application.
Can you help me.

Thanks,
Hari
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls show the result you got, i.e. the HTML code.
Regards,
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using something like
Because if you are, you should remove the entities and just use(the parser won't complain now because it doesn't try to parse the contents of a CDATA block.
[ October 23, 2003: Message edited by: Lasse Koskela ]
 
Hari Shankar Gentyala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse and Tony,
I am using <![CDATA[<font color="red">]]> but my HTML output is not changing the font to red but instead it displays this output.

<font color="red"> CROSS- REFERENCE TO RELATED APPLICATION </font> This <font color="red"> is a continuation of application Ser. No. 08/152,253, filed on Nov. 12, 1993, now abandoned; which is a continuation of Ser. No. 07/864,492 filed on Apr. 7, 1992, now abandoned, which </font> is a continuation of co-pending application Ser. No. 07/160,630 filed on 26 Feb. 1988 now abandoned.
Let me know if i need to modify any code.
Thanks,
Hari
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding <xslutput method="text"/> to the beginning of the stylesheet document.
[ October 23, 2003: Message edited by: Lasse Koskela ]
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTML code looks good, it presents correct color in my IE.
Just a reminder, don't use IE's internal xslt transformer to display your xml with the xsl as href. In that case, the html markup is disabled so you will see the HTML code as it is. So <font color="red">xxxx</font> won't be marked up as red letters. Instead, text as they are will be displayed. Use something like xalan or xt to transform and pipe the code to a browser.
Ignore if it doesn't apply. In any events, html code is good now. problem is within the browser markup step.
Regards
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTML code looks good, it presents correct color in my IE.
Just a reminder, don't use IE's internal xslt transformer to display your xml with the xsl as href. In that case, the html markup is disabled so you will see the HTML code as it is. So <font color="red">xxxx</font> won't be marked up as red letters. Instead, text as they are will be displayed. Use something like xalan or xt to transform and pipe the code to a browser.
Ignore if it doesn't apply. In any events, html code is good now. problem is within the browser markup step.
Regards
 
Hari Shankar Gentyala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lasse and Tony,
It is working fine now.
Thanks again
Hari
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic