• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

xslt : add condition to check for value

I need to add a condition to my transform, but don't know the proper syntax. In my transform, I'm concatenating a couple of values (from URL1 and URLNote1) to build url links. Problem is: Sometimes there's no content in URLNote1, and when that's the case I want to insert "Related File" in place of the missing URLNote1 content. See my snippet below. How do I adjust it so that I'll end up with <a href="URL1">Related File</a> when there's no content in URLNote1?
Please provide the code. - Thanks
<xsl:for-each select="inmr0:URL1[string(.)]">
<PropertyValue name="ClickTitle">Related files available. Click title for access.</PropertyValue>
<PropertyValue name="Link1">
<xsl:value-of select="concat( '&lt;A href=&quot;http://host08.domain.com', .,'&quot;&gt;')"/>
<xsl:for-each select="/inmr0:Textbase_recordset/inmr0:record[$rec-num]/inmr0:URLNote1[string(.)]">
<xsl:value-of select="concat(.,'&lt;/A&gt;')"/>
</xsl:for-each>
</PropertyValue>
</xsl:for-each>

Open in new window

0
GessWurker
Asked:
GessWurker
  • 4
  • 2
1 Solution
 
kmartin7Commented:
Something like the following should work:
<xsl:template match="URLNote1">
		<xsl:choose>
			<xsl:when test="normalize-space(.) = ''">
				<xsl:text>Related Links</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

Open in new window

0
 
GessWurkerAuthor Commented:
Hmm... can't get it to work. Please advise. I've attached the complete xsl. I just need to get the condition working with "Link1."
testXSLT.txt
0
 
GessWurkerAuthor Commented:
Here's my test input
testInput.txt
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
GessWurkerAuthor Commented:
Got it working. See fixed snippet. Thanks for your help.
<xsl:for-each select="inmr0:URL1[string(.)]">
<PropertyValue name="ClickTitle">
<xsl:text>Related files available. Click title for access.</xsl:text>
</PropertyValue>
<PropertyValue name="Link1">
<xsl:value-of select="concat( '&lt;A href=&quot;http://host08.inmagic.com', .,'&quot;&gt;')"/>
<xsl:choose>
<xsl:when test="/inmr0:Textbase_recordset/inmr0:record[$rec-num]/inmr0:URLNote1[string(.)]">
<xsl:for-each select="/inmr0:Textbase_recordset/inmr0:record[$rec-num]/inmr0:URLNote1[string(.)]">
<xsl:value-of select="concat(.,'&lt;/A&gt;')"/>
</xsl:for-each>
</xsl:when>
<xsl:when test="normalize-space(/inmr0:Textbase_recordset/inmr0:record[$rec-num]/inmr0:URLNote1[string(.)])=''">
<xsl:text>Related Links&lt;/A&gt;</xsl:text>
</xsl:when>
</xsl:choose>
</PropertyValue>
</xsl:for-each>

Open in new window

0
 
GessWurkerAuthor Commented:
Had to make some changes and fill in some extra details, but you pointed the way. Thanks.
0
 
kmartin7Commented:
Sorry - I have been away from my desk. Glad you got it working.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now