Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    XSLT Decision making

    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

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by javaguy1007 View Post
    Hi All

    I am working on XSLT

    I have a XML as follows
    Code:
    ?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
    Code:
    <xsl:apply-templates select="/rss/channel/item" mode = "update"/>
    and
    Code:
    <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
    Code:
    <xsl: if test = "rss/channel/title = "update">
         processing here
    Also I have to write something like
    Code:
    <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:
    Code:
    <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

  • Users who have thanked oesxyl for this post:

    javaguy1007 (04-07-2009)

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    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:
    Code:
    <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

    Code:
    <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

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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:
    Code:
    <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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •