Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2010, 06:14 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default Check the conditional expression inside the templace

I have the XML source document:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<HELPDESK>
<board  group="PATHS" >
<board id="AC659FDE" group="PATH" source="C21D8443" target="09CF5CC8"/>
<board id="1C16BEC0" group="PATH" source="C21D8443" target="01DF2C05"/>
<board id="44D44B40" group="PATH" source="C21D8443" target="44A824A6"/>
<board id="1621GUJ00" group="PATH" source="C21D8443" target="44A824A7"/>
</board>

<board group="PRIVATE_ADDRESS">
<board id="C21D8443" group="CENTRE"/>
<board id="C21D8444" group="ADDRESS1"/>
<board id="01DF2C05" group="ADDRESS2" />
<board id="09CF5CC8" group="ADDRESS3" />
</board>

<board group="PUBLIC_PLACES" >
<board id="44A824A6" group="POSTOFFICE"/>
<board id="44A824A7" group="MARKET"/>
</board>
</HELPDESK>
----
My problem is to check if the target is not Public_places and print out the link with that information.
My template starts from board[group="CENTRE"]. How to print the information which shows the private address not the public places in the list?
Could you complete the conditional expression? [And] means only print the target place which not in public_places list
Code:
<xsl:template match="board[group='CENTRE']" mode="center">
<xsl:variable name="starting" select="."/> 
	<xsl:for-each select="$starting">		
		<letgo>
		 <xsl:attribute name="id"> <xsl:value-of select="@id"/> </xsl:attribute>
		 <xsl:attribute name="startat"> <xsl:value-of select="@group"/> </xsl:attribute>
		 <xsl:for-each select="../../board[group='PATH]">
		 <xsl:if test="$starting[@id = current()/@source] and"  >
			<guidedirection>
				<xsl:attribute name="id"> <xsl:value-of select="@id"/> </xsl:attribute>
				<xsl:element name="startingpoint"> <xsl:value-of select="@source"/> </xsl:element>
				<xsl:element name="destination"> <xsl:value-of select="@target"/> </xsl:element>					
			</guidedirection>
		 </xsl:if>
	         </xsl:for-each>
		</letgo>		
	</xsl:for-each>
</xsl:template>

Last edited by metinhoclam; August 12th, 2010 at 06:28 PM..
 
Old August 12th, 2010, 06:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>How to print the information which shows the private address not the public places in the list?

Sorry, I don't understand what that means in terms of your data.

Your code is rather convoluted and I would start by changing it to something like this:

Code:
<xsl:template match="board[group='CENTRE']" mode="center">
  <letgo id="{@id}" startat="{@group}">
  <xsl:for-each select="//board[@group='PATH and @source=current()/@id]">
    <guidedirection id="{@id}">
      <startingpoint> 
         <xsl:value-of select="@source"/>
      </startingpoint>
      <destination>
         <xsl:value-of select="@target"/>  
      </destination>
    </guidedirection>
  </xsl:for-each>
  </letgo>		
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 12th, 2010, 06:47 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default check conditional expression

@mhkay's : It looks better with your modifying. But with that template, we can export all path. I means just export the information which have target not in public place.
<board id="AC659FDE" group="PATH" source="C21D8443" target="09CF5CC8"/>
<board id="1C16BEC0" group="PATH" source="C21D8443" target="01DF2C05"/>
not for all.
 
Old August 12th, 2010, 06:58 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Add a global variable containing all the public places ids:

Code:
<xsl:variable name="public-ids" select="//board[@group='PUBLIC PLACES']/group/@id"/>
and then add to the xsl:for-each

Code:
<xsl:for-each select="//board[@group='PATH 
                              and @source=current()/@id 
                              and not(@target=$public-ids)]">
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 13th, 2010, 05:52 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default It works!

@mr.mhkay: it works...thanks you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing and using an ActiveX from inside a HTML page hosted inside a WebBrowser con adyrotaru C# 2005 2 June 25th, 2009 04:21 PM
Connect to VSS check-in Check-out Programatically rhd110 General .NET 6 August 12th, 2007 07:46 AM
Message> in query expression <expression>. (Error ybg1 Access 5 July 15th, 2007 05:42 AM
Help 'Check ListView' vs 'Check ListBox' MikeY C# 1 February 24th, 2005 02:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.