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 October 12th, 2011, 11:37 AM
Registered User
 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question How to Use 'When' Within 'Translate'

I'm very new to XSLT, and have inherited what is to me a difficult problem. We recieve XML output from a third-party application that is transformed so that it can be used in a COBOL copybook.

It contains a translate function to reduce the size of the input to one character. The translation needs a 'when' so that if <coverage-type> = 'COVA' and <loss-type> = 'Flood' then it is translated to 'F', but if <coverage-type> = 'COVA' and <loss-type> is anything else it translates to 'A'.

I've looked all over the net and in several XSLT books and I can't find anything on a translate function in this format. I've made a try to insert a 'when', but it isn't working.

Error: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 247, position 24.

Saxon
Windows XP

Here's the original code snippet:

Code:
<CopyBookField>
<CopyBookName type="String">CWS-MAJOR-PERIL</CopyBookName>
		<FieldValue type="String" />
		<FieldType type="String">String</FieldType>
		<FieldSize type="int">1</FieldSize>
		<CopyBookPosition type="int">7</CopyBookPosition>
		<NeedsTransformation type="boolean">true</NeedsTransformation>
		<TransformationRule type="com.stoneriver.extract.entity.TranslationRule[]" Function="Translate">
		     <Rule From="COVA" To="A"/>
		     <Rule From="COVB" To="B"/>
		     <Rule From="COVC" To="C"/>
		     <Rule From="COVD" To="D"/>
		     <Rule From="COVE" To="E"/>
		     <Rule From="COVF" To="F"/>
		</TransformationRule>
		<Delegator type="String">XPATH</Delegator>
		<XpathField type="String">sr:Coverage-Type</XpathField>
</CopyBookField>

Here's my attempt to add the needed 'when':

Code:
<CopyBookField>
<CopyBookName type="String">CWS-MAJOR-PERIL</CopyBookName>
		<FieldValue type="String" />
		<FieldType type="String">String</FieldType>
		<FieldSize type="int">1</FieldSize>
		<CopyBookPosition type="int">7</CopyBookPosition>
		<NeedsTransformation type="boolean">true</NeedsTransformation>
		<TransformationRule type="com.stoneriver.extract.entity.TranslationRule[]" Function="Translate">
		     <Rule From="COVA" To="
                                  <xsl:choose>
                                  <xsl:when test="@Coverage-Type='COVA'"     and="@Loss-Type='Terrorism'">
                                   "T"
                                   </xsl:when>    
                                   <xsl:otherwise>
                                   "A"
                                   </xsl:otherwise>
                                   </xsl:choose>"/>
		     <Rule From="COVB" To="B"/>
		     <Rule From="COVC" To="C"/>
		     <Rule From="COVD" To="D"/>
		     <Rule From="COVE" To="E"/>
		     <Rule From="COVF" To="F"/>
		</TransformationRule>
		<Delegator type="String">XPATH</Delegator>
		<XpathField type="String">sr:Coverage-Type</XpathField>
</CopyBookField>

I appreciate any help.
Thanks,
JR
 
Old October 12th, 2011, 11:43 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you really want to put XML markup in an attribute value then you need to escape any "<" as
Code:
&lt;
.

Whether that has any meaning then in the context of your XML format with transformation rules I have no idea.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 12th, 2011, 12:03 PM
Registered User
 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Martin,
I'm not sure it needs to be inside and attribute, I just don't know any other way to do it.

I'm wide open to any suggestions.

Thanks.
 
Old October 12th, 2011, 12:12 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

My suggestion is to find someone (probably in some forum dedicated to the technology you use) that is familiar with that XML format you use and knows whether and if so how you can integrate some XSLT in it. I don't know that format and I have never seen it used to mentioned in this forum so chances are low you will find help here.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to translate C# code to VB bex ASP.NET 2.0 Basics 2 February 14th, 2009 03:25 PM
Can you translate? ms_sheila CSS Cascading Style Sheets 2 May 13th, 2007 08:54 PM
translate gantait XSLT 1 February 27th, 2007 04:15 AM
How do you translate an apostrophe? IronStar XSLT 2 November 13th, 2006 12:35 PM
how to translate this coding sime_tyres Pro VB 6 0 January 17th, 2006 09:32 PM





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