...

View Full Version : XSLT Decision making



javaguy1007
04-07-2009, 04:21 AM
Hi All

I am working on XSLT

I have a XML as follows

?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>
Update
</title>
<link>
myurl
</link>
<description>
</description>
<language>
en-us
</language>
<item>
<title>
title of item1
</title>
<link>
link of item1
</link>
<description>
description of item 1
</description>
</item>
<item>
......
..........
.......
</item>

now I am wiriting xsl

I have to write seperate mode for the value in title tag (Update) and if it is delete , another mode.

Can some one help me how to make decision ,
something like
<xsl:apply-templates select="/rss/channel/item" mode = "update"/>

and

<xsl:template match="/rss/channel/item" mode="save" >
here can I have to write some thing like , I need help in writing following decision making condition
<xsl: if test = "rss/channel/title = "update">
processing here

Also I have to write something like

<xsl:template match="/rss/channel/item" mode="delete" >
<xsl: if test = "rss/channel/title = "delete">
processing here

Thanks
Java guy

oesxyl
04-07-2009, 06:08 AM
Hi All

I am working on XSLT

I have a XML as follows


?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>
Update
</title>
<link>
myurl
</link>
<description>
</description>
<language>
en-us
</language>
<item>
<title>
title of item1
</title>
<link>
link of item1
</link>
<description>
description of item 1
</description>
</item>
<item>
......
..........
.......
</item>

now I am wiriting xsl

I have to write seperate mode for the value in title tag (Update) and if it is delete , another mode.

Can some one help me how to make decision ,
something like


<xsl:apply-templates select="/rss/channel/item" mode = "update"/>

and


<xsl:template match="/rss/channel/item" mode="save" >

here can I have to write some thing like , I need help in writing following decision making condition


<xsl: if test = "rss/channel/title = "update">
processing here

Also I have to write something like


<xsl:template match="/rss/channel/item" mode="delete" >
<xsl: if test = "rss/channel/title = "delete">
processing here

Thanks
Java guy
put your code between [ code] and [ /code] tags without spaces, please. You can edit your previous post to do that. Thank you.

something like this:


<xsl:template match="/">
<xsl:apply-template select="rss/channel"/>
</xsl:template>

<xsl:template match="channel[title = 'Update']">
....
</xsl:template>

<xsl:template match="channel[not(title = 'Update')]">
...
</xsl:template>


but will not work because you can't strip spaces, newlines and cariage return from your title and comparison is case sensitive. The problem is the rss generator, which is poor coded, and striping strings with xslt is a big problem.

best regards

javaguy1007
04-07-2009, 03:13 PM
put your code between [ code] and [ /code] tags without spaces, please. You can edit your previous post to do that. Thank you.

something like this:


<xsl:template match="/">
<xsl:apply-template select="rss/channel"/>
</xsl:template>

<xsl:template match="channel[title = 'Update']">
....
</xsl:template>

<xsl:template match="channel[not(title = 'Update')]">
...
</xsl:template>


but will not work because you can't strip spaces, newlines and cariage return from your title and comparison is case sensitive. The problem is the rss generator, which is poor coded, and striping strings with xslt is a big problem.

best regards

Hi friend

Thanks a lot for your help , But based on the decision , I have to process item tags, how to do that

I mean can I write something like this



<xsl:template match="/">
<xsl:apply-template select="rss/channel"/>
<xsl:apply-templates select="/rss/channel/item"/>
</xsl:template>

<xsl:template match="channel[title = 'Update']">
<xsl:template match="/rss/channel/item" >
....
</xsl:template>
......
</xsl:template>

<xsl:template match="channel[not(title = 'Update')]">
...
</xsl:template>



Please help me
Thanks
Java guy

oesxyl
04-07-2009, 04:32 PM
item is a child of channel, so you don't need to apply template for it in the root node '/', instead you can call apply-template using mode in the channel templates.
will be something like this:


<xsl:template match="/">
<xsl:apply-template select="rss/channel"/>
</xsl:template>

<xsl:template match="channel[title = 'Update']">
<xsl:apply-templates select="item" mode="with-update"/>
....
</xsl:template>

<xsl:template match="channel[not(title = 'Update')]">
<xsl:apply-templates select="item" mode="without-update"/>
...
</xsl:template>

<xsl:template match="item" mode="with-update>
....
</xsl:template>

<xsl:template match="item" mode="without-update>
....
</xsl:template>
......

xml have a tree structure and xslt is xml, so once you are on a node next processing start with the subtree of that node. I hope this will help you to understand why is not neccesary to use a full path like "/rss/channel/item/..." each time you apply a template or write a template for a node.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum