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 December 21st, 2011, 10:56 PM
Registered User
 
Join Date: Dec 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Need help adding if condition

Hello:
I know very little XSL, but need to modify some code to add an if condition. Code (given below) generates filename (e.g. "28867_John_1100002275_D009_List of contents_20111221.pdf"). I need to be able to change part of filename from "List of contents" to "Table of contents". I think code like below should do it but not sure where to add it in code:
Code:
                <xsl:if $DocumentName="List of contents">
                                <xsl:value-of select="Table of contents"/>
                </xsl:if>
Quick help on this will save me a lot of batch processing. Thanks in advance.

Here is the code I need to modify:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:e="http://www.taleo.com/ws/ob800/2009/04" xmlns:fct="http://www.taleo.com/xsl_functions" exclude-result-prefixes="e fct">
	<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
	<xsl:param name="OUTBOUND_FOLDER"/>
	<xsl:template match="/">
	
		<files>
			<xsl:apply-templates select="//e:OnboardingProcessDocument"/>
 <!-- here -->
		</files>
	</xsl:template>
	<xsl:template match="e:OnboardingProcessDocument">
 <!-- here --> 
		<xsl:variable name="EmployeeID" select="../../e:Assignment/e:Assignment/e:TalentMasterFile/e:TalentMasterFile/e:User/e:User/e:EmployeeID"/>
		<xsl:variable name="DocumentCode" select="e:Document/e:FileBasedDocument/e:Code"/>
		<xsl:variable name="DocumentName" select="normalize-space(e:Document/e:FileBasedDocument/e:Name)"/>
		<xsl:variable name="DateCreated" select="../../e:RuntimeFields/e:RuntimeField[@name='Now']"/>
		<xsl:variable name="LastName" select="../../e:Assignment/e:Assignment/e:TalentMasterFile/e:TalentMasterFile/e:User/e:User/e:LastName"/>
		<xsl:variable name="RequisitionNumber" select="../../e:Assignment/e:Assignment/e:Position/e:Position/e:RequisitionNumber"/>
		<xsl:variable name="filename" select="fct:normalize-filename(concat($EmployeeID, '_', $LastName, '_', $RequisitionNumber, '_', $DocumentCode, '_', $DocumentName, '_', $DateCreated, '.pdf'))"/>
		<file path="{concat($OUTBOUND_FOLDER, '/', $filename)}">
			<content>
				<xsl:value-of select="e:content"/>
			</content>
			<Filename>
				<xsl:value-of select="$filename"/>
			</Filename>
			<EmployeeID>
				<xsl:value-of select="$EmployeeID"/>
			</EmployeeID>
			<DocumentCode>
				<xsl:value-of select="$DocumentCode"/>
			</DocumentCode>
			<DocumentName>
				<xsl:value-of select="$DocumentName"/>
			</DocumentName>
			<RequisitionNumber>
				<xsl:value-of select="$RequisitionNumber"/>
			</RequisitionNumber>
			<LastName>
				<xsl:value-of select="$LastName"/>
			</LastName>
			<DateCreated>
				<xsl:value-of select="$DateCreated"/>
			</DateCreated>
		</file>
	</xsl:template>
	<!-- ======================================= -->
	<!-- Normalize filename, replacing invalid characters with '_'. -->
	<!-- ======================================= -->
	<xsl:function name="fct:normalize-filename">
		<xsl:param name="filename"/>
		<xsl:value-of select="replace(replace(translate($filename, '\\\/:*?|', '_'), '&lt;', '_'), '&gt;', '_')"/>
	</xsl:function>
</xsl:stylesheet>
 
Old December 22nd, 2011, 02:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, your syntax isn't quite right. The nearest would be something like

Code:
<xsl:if test="$DocumentName='List of contents'">
     <xsl:value-of select="'Table of contents'"/>
</xsl:if>
though the following is shorter:

Code:
<xsl:if test="$DocumentName='List of contents'">Table of contents</xsl:if>
But then there's the question of where you intend to put this code. You're calculating the filename inside a function where the variable $DocumentName isn't available. So you may need to add it as an extra paramter.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
kakhtar (December 22nd, 2011)
 
Old December 22nd, 2011, 02:52 PM
Registered User
 
Join Date: Dec 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Michael.
Unfortunately I am novice trying to make this code work. Would you be kind enough to modify as needed to achieve desired results?
 
Old December 22nd, 2011, 03:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

No, sorry, I'm prepared to answer questions about XSLT but I'm not prepared to write your code for you. You should not attempt to modify a working stylesheet until you have a basic knowledge of the language.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old December 22nd, 2011, 03:32 PM
Registered User
 
Join Date: Dec 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Fair enough. Thanks for looking into it anyway.
 
Old December 23rd, 2011, 07:47 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

I could not understand ur need. Please post a minimal XML and the expected output from that. Show some examples on your requirement.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the If Condition bex ASP.NET 3.5 Basics 2 June 30th, 2009 02:34 AM
or condition kgoldvas XSLT 1 July 31st, 2007 03:44 AM
where condition...? mnr555 Crystal Reports 0 June 18th, 2006 05:32 PM
if then else condition mateenmohd Classic ASP Basics 0 April 16th, 2005 07:08 AM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM





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