RE: [xsl] FW: Newbie question

Subject: RE: [xsl] FW: Newbie question
From: "David at roamware" <david@xxxxxxxxxxxxxx>
Date: Mon, 6 Dec 2004 18:50:23 -0000
Hi,

Thanks, Tried that, but still no joy? Probably misinterpreted something?

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:t="http://tempuri.org/test.xsd";>
	<xsl:output method="text" indent="no" encoding="ISO-8859-1"/>
	<xsl:template match="/">
<xsl:apply-templates
select="/t:CorporateActionAnnouncement/CorporateAction/GeneralInformationBlo
ck"></xsl:apply-templates>
<xsl:apply-templates
select="/t:CorporateActionAnnouncement/CorporateAction/UnderlyingSecurities"
></xsl:apply-templates>
<xsl:apply-templates
select="/t:CorporateActionAnnouncement/CorporateAction/CorporateActionDetail
"></xsl:apply-templates>
<xsl:apply-templates
select="/t:CorporateActionAnnouncement/CorporateAction/CorporateActionOption
"></xsl:apply-templates>
	</xsl:template>

	<xsl:template match="t:GeneralInformationBlock">
testoutput<xsl:call-template name="funcmsglookup"><xsl:with-param
name="codef" select="t:FunctionofMessage"/></xsl:call-template>
moretestoutput
	</xsl:template>

	<xsl:template match="t:UnderlyingSecurities">
/<xsl:value-of select="t:UnderlyingSecurityISIN/Listing"/>/
	</xsl:template>

	<xsl:template match="t:CorporateActionDetail">
test//<xsl:call-template name="dateformat"><xsl:with-param name="adate"
select="t:RecordDate"/></xsl:call-template>
	</xsl:template>

	<xsl:template match="t:CorporateActionOption">
//<xsl:value-of select="t:CorporateActionOptionNumber"/>
OP//<xsl:call-template name="caoptlookup"><xsl:with-param name="codea"
select="t:CorporateActionOptionsCode"/></xsl:call-template>
LT//<xsl:call-template name="defproclookup"><xsl:with-param name="codep"
select="t:DefaultProcessingFlag"/></xsl:call-template>
	<xsl:if test="t:CashPaymentDetails!=''">
YD//<xsl:value-of select="t:DefaultProcessingFlag"/>
S//<xsl:value-of
select="t:CashPaymentDetails/GrossAmountPayable/Currency"/><xsl:value-of
select="t:CashPaymentDetails/GrossAmountPayable/Currency"/>
	</xsl:if>
	<xsl:if test="t:SecuritiesMovement!=''">
B//<xsl:call-template name="debcredlookup"><xsl:with-param name="codee"
select="t:DebitCreditIndicator"/></xsl:call-template>
MOVE
	</xsl:if>
MOREOUT
	</xsl:template>

	<xsl:template name="funcmsglookup">
		<xsl:param name="codef"/>
		<xsl:if test="codef=0"><xsl:text></xsl:text>NEWM</xsl:if>
		<xsl:if test="codef=1"><xsl:text>REPL</xsl:text></xsl:if>
		<xsl:if test="codef=2"><xsl:text>CANC</xsl:text></xsl:if>
	</xsl:template>

	<xsl:template name="caoptlookup">
		<xsl:param name="codea"/>
		<xsl:if test="codea=0"></xsl:if>
		<xsl:if test="codea=1"><xsl:text>CASH</xsl:text></xsl:if>
		<xsl:if test="codea=2"><xsl:text>SECU</xsl:text></xsl:if>
	</xsl:template>

	<xsl:template name="debcredlookup">
		<xsl:param name="codee"/>
		<xsl:if test="codee=0"></xsl:if>
		<xsl:if test="codee=1"><xsl:text>CRED</xsl:text></xsl:if>
		<xsl:if test="codee=2"><xsl:text>DEBT</xsl:text></xsl:if>
	</xsl:template>

	<xsl:template name="defproclookup">
		<xsl:param name="codep"/>
		<xsl:if test="codep=0"></xsl:if>
		<xsl:if test="codep=1"><xsl:text>Y</xsl:text></xsl:if>
		<xsl:if test="codep=2"><xsl:text>N</xsl:text></xsl:if>
	</xsl:template>

	<xsl:template name="dateformat">
		<xsl:param name="adate"/>

<xsl:text>substring($adate,0,4)substring($adate,5,2)substring($adate,8,2)</x
sl:text>
	</xsl:template>
</xsl:stylesheet>

Regards,

David



-----Original Message-----
From: George Cristian Bina [mailto:george@xxxxxxx]
Sent: 06 December 2004 18:28
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] FW: Newbie question


Hi David,

That is because your XPath expressions match elements from no namespace
while all the elements from your XML file are from
http://tempuri.org/test.xsd namespace:

 > <CorporateActionAnnouncement xmlns="http://tempuri.org/test.xsd";>

You should add in your stylesheet something like

xmlns:t="http://tempuri.org/test.xsd";

and then use the t prefix to refer to any element in your stylesheet,
for instance instead of CorporateActionAnnouncement you should have
t:CorporateActionAnnouncement.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


David at roamware wrote:
> Hi,
>
> I am new to XSLT. I have been using Treebeard as my editor. I get no
errors,
> but also no output. I have spent ages looking at the xsl and cannot see
what
> is wrong. One thing not entirely clear to me is how the context changes,
> this is not well epxlained anywhere I have looked. So I tend to use
absolute
> XPath expressions.
>
> Here is my test.xml
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <CorporateActionAnnouncement xmlns="http://tempuri.org/test.xsd";>
> 	<AnnouncementDetails>
> 		<Released>2004-09-27</Released>
> 	</AnnouncementDetails>
> 	<Announcement>
> 		<Title>test</Title>
> 	</Announcement>
> 	<CorporateAction>
> 		<GeneralInformationBlock>
> 			<FunctionofMessage>2</FunctionofMessage>
> 		</GeneralInformationBlock>
> 		<UnderlyingSecurities>
> 			<UnderlyingSecurityISIN>
> 				<Listing>PLIS</Listing>
> 			</UnderlyingSecurityISIN>
> 		</UnderlyingSecurities>
> 		<CorporateActionDetail>
> 			<RecordDate>2004-08-20</RecordDate>
> 		</CorporateActionDetail>
> 		<CorporateActionOption>
> 			<CorporateActionOptionNumber>001</CorporateActionOptionNumber>
> 			<CorporateActionOptionsCode>Securities
> Option</CorporateActionOptionsCode>
> 			<DefaultProcessingFlag>1</DefaultProcessingFlag>
> 			<CashPaymentDetails>
> 				<PaymentDate>2004-10-06</PaymentDate>
> 			</CashPaymentDetails>
> 			<SecuritiesMovement>
> 				<DebitCreditIndicator></DebitCreditIndicator>
> 			</SecuritiesMovement>
> 		</CorporateActionOption>
> 		<CorporateActionOption>
> 			<CorporateActionOptionNumber>002</CorporateActionOptionNumber>
> 			<CorporateActionOptionsCode>Securities
> Option</CorporateActionOptionsCode>
> 			<DefaultProcessingFlag>2</DefaultProcessingFlag>
> 			<CashPaymentDetails>
> 				<PaymentDate></PaymentDate>
> 			</CashPaymentDetails>
> 			<SecuritiesMovement>
> 				<DebitCreditIndicator>Credit</DebitCreditIndicator>
> 			</SecuritiesMovement>
> 		</CorporateActionOption>
> 	</CorporateAction>
> </CorporateActionAnnouncement>
>
> Here is my xsl
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 	<xsl:output method="text" indent="no" encoding="ISO-8859-1"/>
> 	<xsl:template match="/">
> <xsl:apply-templates
>
select="/CorporateActionAnnouncement/CorporateAction/GeneralInformationBlock
> "></xsl:apply-templates>
> <xsl:apply-templates
>
select="/CorporateActionAnnouncement/CorporateAction/UnderlyingSecurities"><
> /xsl:apply-templates>
> <xsl:apply-templates
>
select="/CorporateActionAnnouncement/CorporateAction/CorporateActionDetail">
> </xsl:apply-templates>
> <xsl:apply-templates
>
select="/CorporateActionAnnouncement/CorporateAction/CorporateActionOption">
> </xsl:apply-templates>
> 	</xsl:template>
>
> 	<xsl:template match="GeneralInformationBlock">
> testoutput<xsl:call-template name="funcmsglookup"><xsl:with-param
> name="codef" select="FunctionofMessage"/></xsl:call-template>
> moretestoutput
> 	</xsl:template>
>
> 	<xsl:template match="UnderlyingSecurities">
> /<xsl:value-of select="UnderlyingSecurityISIN/Listing"/>/
> 	</xsl:template>
>
> 	<xsl:template match="CorporateActionDetail">
> test//<xsl:call-template name="dateformat"><xsl:with-param name="adate"
> select="RecordDate"/></xsl:call-template>
> 	</xsl:template>
>
> 	<xsl:template match="CorporateActionOption">
> //<xsl:value-of select="CorporateActionOptionNumber"/>
> OP//<xsl:call-template name="caoptlookup"><xsl:with-param name="codea"
> select="CorporateActionOptionsCode"/></xsl:call-template>
> LT//<xsl:call-template name="defproclookup"><xsl:with-param name="codep"
> select="DefaultProcessingFlag"/></xsl:call-template>
> 	<xsl:if test="CashPaymentDetails!=''">
> YD//<xsl:value-of select="DefaultProcessingFlag"/>
> S//<xsl:value-of
> select="CashPaymentDetails/GrossAmountPayable/Currency"/><xsl:value-of
> select="CashPaymentDetails/GrossAmountPayable/Currency"/>
> 	</xsl:if>
> 	<xsl:if test="SecuritiesMovement!=''">
> B//<xsl:call-template name="debcredlookup"><xsl:with-param name="codee"
> select="DebitCreditIndicator"/></xsl:call-template>
> MOVE
> 	</xsl:if>
> MOREOUT
> 	</xsl:template>
>
> 	<xsl:template name="funcmsglookup">
> 		<xsl:param name="codef"/>
> 		<xsl:if test="codef=0"><xsl:text></xsl:text>NEWM</xsl:if>
> 		<xsl:if test="codef=1"><xsl:text>REPL</xsl:text></xsl:if>
> 		<xsl:if test="codef=2"><xsl:text>CANC</xsl:text></xsl:if>
> 	</xsl:template>
>
> 	<xsl:template name="caoptlookup">
> 		<xsl:param name="codea"/>
> 		<xsl:if test="codea=0"></xsl:if>
> 		<xsl:if test="codea=1"><xsl:text>CASH</xsl:text></xsl:if>
> 		<xsl:if test="codea=2"><xsl:text>SECU</xsl:text></xsl:if>
> 	</xsl:template>
>
> 	<xsl:template name="debcredlookup">
> 		<xsl:param name="codee"/>
> 		<xsl:if test="codee=0"></xsl:if>
> 		<xsl:if test="codee=1"><xsl:text>CRED</xsl:text></xsl:if>
> 		<xsl:if test="codee=2"><xsl:text>DEBT</xsl:text></xsl:if>
> 	</xsl:template>
>
> 	<xsl:template name="defproclookup">
> 		<xsl:param name="codep"/>
> 		<xsl:if test="codep=0"></xsl:if>
> 		<xsl:if test="codep=1"><xsl:text>Y</xsl:text></xsl:if>
> 		<xsl:if test="codep=2"><xsl:text>N</xsl:text></xsl:if>
> 	</xsl:template>
>
> 	<xsl:template name="dateformat">
> 		<xsl:param name="adate"/>
>
>
<xsl:text>substring($adate,0,4)substring($adate,5,2)substring($adate,8,2)</x
> sl:text>
> 	</xsl:template>
> </xsl:stylesheet>
>
> where am I going wrong?
>
> Thx.
>
> David

Current Thread