XSLT date format using substring - xslt-1.0

My requirement is to make a webservice call passing a date so that I get all records back that have been changed since that date. I'm using Stylist Studio 2011 for my development. I've managed to get a date minus 2 days, but it always returns with a time: i.e. 2015-06-20-05:00 but I only want the date without the time. I have tried substring as in the following example and date format, but I get an empty result.
This code returns with time:
{<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="vToday" select="current-date()"/>
<v1:lastChanged>
<xsl:value-of select="$vToday -2*xs:dayTimeDuration('P1D')"/>
</v1:lastChanged>
</xsl:template>
</xsl:stylesheet>
}
Results are:
{
<v1:lastChanged xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/">2015-06-20-05:00</v1:lastChanged>
}
This is my substring attempt
{<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="vToday" select="current-date()"/>
<xsl:variable name="vTodayTrim" select="$vToday -2*xs:dayTimeDuration('P1D')"/>
<xsl:variable name="vTodayDate" fn:substring="(vTodayTrim,1 ,10)"/>
<v1:lastChanged>
<xsl:value-of select="vTodayDate"/>
</v1:lastChanged>
</xsl:template>
</xsl:stylesheet>
}
This is my result:
{`<v1:lastChanged xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/"/>`
}
I've tried multiple variations of all this and the best I can say is I get consistent results. I'm only chasing my tale at this point.
I solved this one on my own. Here is what have working now:
{
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mro="http://www.ibm.com/maximo"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="vToday" select="current-date()"/>
<xsl:variable name="vTodayTrim" select="$vToday -2*xs:dayTimeDuration('P1D')"/>
<v1:lastChanged>
<xsl:value-of select="substring($vTodayTrim,1,10)"/>
</v1:lastChanged>
</xsl:template>
</xsl:stylesheet>
}
and I get back
{
<v1:lastChanged xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mro="http://www.ibm.com/maximo" xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/">2015-06-20</v1:lastChanged>
}
So my new approach since my application doesn't support 2.0 is to set the value in xml prior to putting it through the xslt as in the following (lastChanged tag near bottom of xml - this is output in the logfile):
{
<InvokeNASAPERSON xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2015-06-25T11:30:04-05:00" transLanguage="EN" baseLanguage="EN" messageID="1435249805139258092" maximoVersion="7 5 20130829-1209 V7510--1">
<NASAPERSONSet>
<PERSON>
<DEPARTMENT />
<DISPLAYNAME>MAXADMIN</DISPLAYNAME>
<DROPPOINT />
<FIRSTNAME />
<LASTNAME />
<LOCATION />
<LOCATIONORG />
<NASACENTER />
<NASAFUNDINGORG />
<NP_STATUSMEMO />
<OWNERSYSID />
<PERSONID>MAXADMIN</PERSONID>
<PERSONUID>3</PERSONUID>
<PRIMARYEMAIL>jreeve#cohesivesolutions.com</PRIMARYEMAIL>
<PRIMARYPHONE>423 314 1312</PRIMARYPHONE>
<SENDERSYSID>MX</SENDERSYSID>
<SOURCESYSID />
<STATUS maxvalue="ACTIVE">ACTIVE</STATUS>
<STATUSDATE>2004-04-14T11:58:32-05:00</STATUSDATE>
<STATUSIFACE>0</STATUSIFACE>
<SUPERVISOR />
<TITLE />
<PHONE>
<ISPRIMARY>1</ISPRIMARY>
<PHONEID>82</PHONEID>
<PHONENUM>423 314 1312</PHONENUM>
<TYPE />
</PHONE>
<EMAIL>
<EMAILADDRESS>jreeve#cohesivesolutions.com</EMAILADDRESS>
<EMAILID>122</EMAILID>
</EMAIL>
<lastChanged>2015-06-23</lastChanged>
</PERSON>
</NASAPERSONSet>
</InvokeNASAPERSON>
}
My xslt seems to work when I test it in stylist studio. Here is the current xslt
{
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mro="http://www.ibm.com/maximo" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://types.msfc.nasa.gov/personnel/messages/v1/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/mro:InvokeNASAPERSON/mro:NASAPERSONSet/mro:PERSON">
<v1:PersonQueryRequest>
<v1:lastChanged>
<xsl:value-of select="mro:lastChanged"/>
</v1:lastChanged>
</v1:PersonQueryRequest>
</xsl:template>
</xsl:stylesheet>
}
and the stacktrace
{End of input XML
[6/25/15 11:30:06:075 CDT] 00000120 SystemOut O 25 Jun 2015 11:30:06:075 [ERROR] [MXServer] [CID-CRON-265] com.ibm.xtq.xslt.jaxp.HandledRuntimeException: [ERR 0641] An error occurred while parsing document: 'Content is not allowed in prolog.'.
javax.xml.transform.TransformerConfigurationException: com.ibm.xtq.xslt.jaxp.HandledRuntimeException: [ERR 0641] An error occurred while parsing document: 'Content is not allowed in prolog.'.
at com.ibm.xtq.xslt.jaxp.AbstractTransformerFactory.newTemplates(Unknown Source)
at psdi.common.xsl.XSLTransformerCache.createTransformer(XSLTransformerCache.java:96)
at psdi.common.xsl.XSLTransformerCache.getTransformer(XSLTransformerCache.java:67)
at psdi.common.xsl.XSLTransformer.getTransformerFromPath(XSLTransformer.java:143)
at psdi.common.xsl.XSLTransformer.transform(XSLTransformer.java:129) at psdi.iface.migexits.ExitProcessor.mapData(ExitProcessor.java:607)
at psdi.iface.migexits.ExitProcessor.executeOutExitLogic(ExitProcessor.java:458)
at psdi.iface.migexits.ExitProcessor.processTheseExitsOut(ExitProcessor.java:342)
at psdi.iface.migexits.ExitProcessor.processExitsOut(ExitProcessor.java:157)
at psdi.iface.mic.InvokeChannel.processExitsOut(InvokeChannel.java:329)
at psdi.iface.mic.InvokeChannel.invoke(InvokeChannel.java:102)
at psdi.iface.action.InvokeCustomClass.applyCustomAction(InvokeCustomClass.java:109)
at psdi.common.action.Action.executeCustomClass(Action.java:399)
at psdi.common.action.Action.executeAction(Action.java:311)
at psdi.common.action.Action.executeActionGroup(Action.java:365)
at psdi.common.action.Action.executeAction(Action.java:331)
at psdi.common.action.Action.executeAction(Action.java:344)
at psdi.app.escalation.engine.EscalationTask.executeAction(EscalationTask.java:1454)
at psdi.app.escalation.engine.EscalationTask.executeActions(EscalationTask.java:1372)
at psdi.app.escalation.engine.EscalationTask.executeReferencePoint(EscalationTask.java:622)
at psdi.app.escalation.engine.EscalationTask.processReferencePoint(EscalationTask.java:520)
at psdi.app.escalation.engine.EscalationTask.performTask(EscalationTask.java:175)
at psdi.app.escalation.engine.EscalationCronTask.cronAction(EscalationCronTask.java:46)
at psdi.server.CronTaskManager.callCronMethod(CronTaskManager.java:1590)
at psdi.server.CronTaskManager.access$400(CronTaskManager.java:87)
at psdi.server.CronTaskManager$CronThread.run(CronTaskManager.java:2156)
Caused by: com.ibm.xtq.xslt.jaxp.HandledRuntimeException: [ERR 0641] An error occurred while parsing document: 'Content is not allowed in prolog.'.
at com.ibm.xtq.xslt.jaxp.ConfigurationErrorHandler.report(Unknown Source)
at com.ibm.xtq.utils.Reporter.report(Unknown Source)
at com.ibm.xtq.ast.parsers.xslt.XSLTParser.reportError(Unknown Source)
at com.ibm.xtq.ast.parsers.xslt.XSLTParser.parse(Unknown Source)
at com.ibm.xtq.ast.parsers.xslt.XSLTParser.parse(Unknown Source)
at com.ibm.xtq.xslt.drivers.XSLTCompiler.makeAST(Unknown Source)
at com.ibm.xtq.xslt.drivers.XSLTCompiler.buildAST(Unknown Source)
at com.ibm.xtq.xslt.drivers.XSLTCompiler.compile(Unknown Source)
at com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl.createTemplates(Unknown Source)
... 26 more
[6/25/15 11:30:06:090 CDT] 00000120 SystemOut O 25 Jun 2015 11:30:06:075 [ERROR] [MXServer] [CID-CRON-265] Failed to execute action on escalation: {NASAPERSONWS} reference point: {155} for object {PERSON} with id {3}
psdi.util.MXSystemException: BMXAA4214E - An unknown error has occurred.
Please contact your system administrator for assistance. Gather the logs from the <HOME> directory and determine where and why the error is thrown.
com.ibm.xtq.xslt.jaxp.HandledRuntimeException: [ERR 0641] An error occurred while parsing document: 'Content is not allowed in prolog.'.
at psdi.iface.migexits.ExitProcessor.mapData(ExitProcessor.java:630)
at psdi.iface.migexits.ExitProcessor.executeOutExitLogic(ExitProcessor.java:458)
at psdi.iface.migexits.ExitProcessor.processTheseExitsOut(ExitProcessor.java:342)
at psdi.iface.migexits.ExitProcessor.processExitsOut(ExitProcessor.java:157)
at psdi.iface.mic.InvokeChannel.processExitsOut(InvokeChannel.java:329)
at psdi.iface.mic.InvokeChannel.invoke(InvokeChannel.java:102)
at psdi.iface.action.InvokeCustomClass.applyCustomAction(InvokeCustomClass.java:109)
at psdi.common.action.Action.executeCustomClass(Action.java:399)
at psdi.common.action.Action.executeAction(Action.java:311)
at psdi.common.action.Action.executeActionGroup(Action.java:365)
at psdi.common.action.Action.executeAction(Action.java:331)
at psdi.common.action.Action.executeAction(Action.java:344)
at psdi.app.escalation.engine.EscalationTask.executeAction(EscalationTask.java:1454)
at psdi.app.escalation.engine.EscalationTask.executeActions(EscalationTask.java:1372)
at psdi.app.escalation.engine.EscalationTask.executeReferencePoint(EscalationTask.java:622)
at psdi.app.escalation.engine.EscalationTask.processReferencePoint(EscalationTask.java:520)
at psdi.app.escalation.engine.EscalationTask.performTask(EscalationTask.java:175)
at psdi.app.escalation.engine.EscalationCronTask.cronAction(EscalationCronTask.java:46)
at psdi.server.CronTaskManager.callCronMethod(CronTaskManager.java:1590)
at psdi.server.CronTaskManager.access$400(CronTaskManager.java:87)
at psdi.server.CronTaskManager$CronThread.run(CronTaskManager.java:2156)
Caused by: javax.xml.transform.TransformerConfigurationException: com.ibm.xtq.xslt.jaxp.HandledRuntimeException: [ERR 0641] An error occurred while parsing document: 'Content is not allowed in prolog.'.
at com.ibm.xtq.xslt.jaxp.AbstractTransformerFactory.newTemplates(Unknown Source)
at psdi.common.xsl.XSLTransformerCache.createTransformer(XSLTransformerCache.java:96)
at psdi.common.xsl.XSLTransformerCache.getTransformer(XSLTransformerCache.java:67)
at psdi.common.xsl.XSLTransformer.getTransformerFromPath(XSLTransformer.java:143)
at psdi.common.xsl.XSLTransformer.transform(XSLTransformer.java:129)
at psdi.iface.migexits.ExitProcessor.mapData(ExitProcessor.java:607)
... 20 more
Caused by: com.ibm.xtq.xslt.jaxp.HandledRuntimeException: [ERR 0641] An error occurred while parsing document: 'Content is not allowed in prolog.'.
at com.ibm.xtq.xslt.jaxp.ConfigurationErrorHandler.report(Unknown Source)
at com.ibm.xtq.utils.Reporter.report(Unknown Source)
at com.ibm.xtq.ast.parsers.xslt.XSLTParser.reportError(Unknown Source)
at com.ibm.xtq.ast.parsers.xslt.XSLTParser.parse(Unknown Source)
at com.ibm.xtq.ast.parsers.xslt.XSLTParser.parse(Unknown Source)
at com.ibm.xtq.xslt.drivers.XSLTCompiler.makeAST(Unknown Source)
at com.ibm.xtq.xslt.drivers.XSLTCompiler.buildAST(Unknown Source)
at com.ibm.xtq.xslt.drivers.XSLTCompiler.compile(Unknown Source)
at com.ibm.xtq.xslt.jaxp.compiler.TransformerFactoryImpl.createTemplates(Unknown Source)
... 26 more
}

This last approach was correct, I just fat fingered by filename when referencing the xsl call. This issues is resolved.

Related

How to read Data from a file using XSLT in IBM API connect

I am working on creating REST API's in IBM API connect. our requirement is to get the backend URL's from a property file which is present on the datapower gateway server and then invoke the back-end service in the API's.
In API assembly I have written the XSLT code to open the file and read the data from the file, but the xslt is returning an empty response.
XSLT Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:func="http://exslt.org/functions"
xmlns:apim="http://www.ibm.com/apimanagement"
extension-element-prefixes="dp func apim"
exclude-result-prefixes="dp func apim">
<!-- Cotains the APIM functions -->
<xsl:import href="local:///isp/policy/apim.custom.xsl"/>
<xsl:template match="/">
<xsl:variable name="FileContent">
<dp:url-open target="'https://localhost:9090/dp'" response="xml" data-type="filename">local:///policy/propertyfiles/URLs.xml
</dp:url-open>
</xsl:variable>
<xsl:variable name="policy-props" select="apim:policyProperties()"/>
<xsl:variable name="catalog" select="apim:getContext('env.path')"/>
<outputXml>
<data><xsl:copy-of select="$FileContent" /></data>
<catalog><xsl:value-of select="$catalog" /></catalog>
<xsl:for-each select="$FileContent/catalogs/catalog">
<xsl:variable name="ReferencedID" select="#name"/>
<xsl:choose>
<xsl:when test="$ReferencedID = $catalog">
<backend_url><xsl:value-of select="$FileContent/response/catalogs/catalog/backend_url" /></backend_url>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</outputXml>
</xsl:template>
</xsl:stylesheet>
I am expecting to see the data from the file in the xslt response . But I see the below response which is missing the data from the file.
Body:
<?xml version="1.0" encoding="UTF-8"?>
<outputXml>
<data/>
<catalog>sb</catalog>
</outputXml>
Either use dp:url-open or possibly the document() function.
Another option is to add a GWS action to read the file and set it in a context variable.
Use below XSLT code it will capture Reques-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"
xmlns:func="http://exslt.org/functions"
xmlns:apim="http://www.ibm.com/apimanagement" extension-element-prefixes="dp func apim" exclude-result-prefixes="xsl dp func apim">
<!-- Contains the APIM functions -->
<xsl:import href="local:///isp/policy/apim.custom.xsl" />
<xsl:template match="/">
<xsl:variable name="input" select="apim:payloadRead()" />
<xsl:message>
The input payload is
<xsl:copy-of select="$input" />
</xsl:message>
</xsl:template>
</xsl:stylesheet>

Using XSLT to visit child nodes and retrieve element values

Using the following input XML, my goal is to initially select portfolios/portfolio node, then the <tradeContribution> child nodes - specifically contributions/tradeContribution .
These tradeContribution nodes will then be transformed into the <trade> nodes in the xml output shown below.
My xml output and XSLT code follows below...
<outBound>
<requestReceivedTime>2014-05-15 15:20:42.279</requestReceivedTime>
<responseSentTime>2014-05-15 15:20:42.338</responseSentTime>
<body>
<portfolios>
<portfolio id="36" nodeDate="2014-05-06">
<query>
<firstTerm>
<date>2014-05-06</date>
</firstTerm>
<lastTerm>
<date>2014-05-06</date>
</lastTerm>
</query>
<exposure>492691.50878619519</exposure>
<contributions>
<tradeContribution contextId="0" contribution="267624.242492124" dealId="IRSW-TRADE-00011" desc="IRSW-FIX-FLOAT" order="0" sysId="1" tradeId="IRSW-TRADE-00011">
<hideTrade>false</hideTrade>
<readOnly>false</readOnly>
</tradeContribution>
<tradeContribution contextId="7" contribution="225067.26629407122" dealId="IRSW-TRADE-00020" desc="IRSW-FIX-FLOAT" order="1" sysId="2" tradeId="IRSW-TRADE-00020">
<hideTrade>false</hideTrade>
<readOnly>false</readOnly>
</tradeContribution>
</contributions>
<nodeAnalysis id="HSVaR 5D 100 ES">
<method>INTERPOLATED_EXPECTED_SHORTFALL</method>
<exposure>true</exposure>
<percentile>100</percentile>
</nodeAnalysis>
</portfolio>
</portfolios>
</body>
</outBound>
My desired XML output is:
<?xml version="1.0" ?>
<collection>
<trade>
<legal_id>36</legal_id>
<tradeRef>IRS-RRT-002</tradeRef>
<system>MY SYSTEM IRS</system>
<indepMtmValuation>111111</indepMtmValuation>
<indepMtmValuationCcy>USD</indepMtmValuationCcy>
<principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
<principalDealLevelAmount>14</principalDealLevelAmount>
<principalDealLevelCurrency>USD</principalDealLevelCurrency>
<principalDealLevelType>Independent Amount</principalDealLevelType>
<operation>U</operation>
</trade>
<trade>
<legal_id>36</legal_id>
<system>MY SYSTEM CDS</system>
<tradeRef>CDS-RRT-008</tradeRef>
<mtmValuation>222222</mtmValuation>
<mtmValuationDate>2013-09-11</mtmValuationDate>
<mtmValuationLocalSysCcy>USD</mtmValuationLocalSysCcy>
<counterpartyDealLevelUpfront>TRUE</counterpartyDealLevelUpfront>
<counterpartyDealLevelAmount>15</counterpartyDealLevelAmount>
<counterpartyDealLevelCurrency>JPY</counterpartyDealLevelCurrency>
<counterpartyDealLevelType>Independent Amount</counterpartyDealLevelType>
</trade>
</collection>
The XSLT I have so far is as follows; however, I have a problem:
1) Trying to find the best way to pull the value of attribute "id", which is part of <portfolio id="36" nodeDate="2014-05-06"> .
I need to output it to <legal_id>, but this here is NOT working:
<legal_id><xsl:value-of select="../portfolio[#id]"/></legal_id>
Your advice would be greatly appreciate in helping to properly construct my XSLT to produce the desired XML output shown above:
My XSLT code thus far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="1.0">
<!-- Variable declaration -->
<xsl:variable name="hsVar1D" select="'1D (99%)'"></xsl:variable>
<xsl:variable name="hsVar5D" select="'HSVaR 5D 100 ES'"></xsl:variable>
<xsl:template match="/*">
<collection>
<xsl:apply-templates select="/outbound/body/portfolios/portfolio[descendant::nodeAnalysis[#id[contains(.,$hsVar5D)]]]" />
</collection>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates select="contributions/tradeContribution"/>
</xsl:template>
<xsl:template match="contributions/tradeContribution">
<trade>
<!-- QUESTION: For <legal_id> what is the best way to select the #id attrib from the ancestor node <portfolio> -->
<legal_id><xsl:value-of select="#id"/></legal_id>
<legal_id222><xsl:value-of select="../portfolio[#id]"/></legal_id222>
<tradeRef>IRS-RRT-002</tradeRef>
<system>MY SYSTEM IRS</system>
<indepMtmValuation>111111</indepMtmValuation>
<indepMtmValuationCcy>USD</indepMtmValuationCcy>
<principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
<principalDealLevelAmount><xsl:value-of select="exposure"></xsl:value-of></principalDealLevelAmount>
<principalDealLevelCurrency>USD</principalDealLevelCurrency>
<principalDealLevelType>Independent Amount</principalDealLevelType>
<operation>U</operation>
</trade>
</xsl:template>
Try it this way:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- Variable declaration -->
<xsl:variable name="hsVar1D" select="'1D (99%)'"></xsl:variable>
<xsl:variable name="hsVar5D" select="'HSVaR 5D 100 ES'"></xsl:variable>
<xsl:template match="/">
<collection>
<xsl:apply-templates select="outBound/body/portfolios/portfolio[nodeAnalysis[contains(#id,$hsVar5D)]]/contributions/tradeContribution" />
</collection>
</xsl:template>
<xsl:template match="tradeContribution">
<trade>
<legal_id>
<xsl:value-of select="../../../portfolio/#id"/>
</legal_id>
<tradeRef>IRS-RRT-002</tradeRef>
<system>RAZOR IRS</system>
<indepMtmValuation>111111</indepMtmValuation>
<indepMtmValuationCcy>USD</indepMtmValuationCcy>
<principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
<principalDealLevelAmount>
<xsl:value-of select="../../nodeAnalysis/exposure"/>
</principalDealLevelAmount>
<principalDealLevelCurrency>USD</principalDealLevelCurrency>
<principalDealLevelType>Independent Amount</principalDealLevelType>
<operation>U</operation>
</trade>
</xsl:template>
</xsl:stylesheet>
--
Note outBound vs. razorOutbound

Xslt to copy inner xml without unused namespaces

I wish to remove a couple of unused namespaces from a resulting output from an xslt stylesheet.
The xml to feed in is a wrapper around another xml message which is seen in the BodyMessage element. An example of the entire xml can bee seen below:
<?xml version="1.0" encoding="utf-8"?>
<ns0:Wrapper xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0" xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0">
<TaskName>SomeTaskName</TaskName>
<TaskStatus>Start</TaskStatus>
<Id>Y/0070/0010</Id>
<BodyMessage>
<tva:TVAMain rightsOwner="FAIRY" xmlns:tva="urn:tva:metadata:2004">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
</tva:TVAMain>
</BodyMessage>
</ns0:Wrapper>
When I try to extract the xml out of the BodyMessage element I get unused namespaces returned
xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0"
xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0"
These are not required but I do not understand how to remove them within my xslt.
Please note I DO want to keep
xmlns:tva="urn:tva:metadata:2004"
The stylesheet I used is:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tva="urn:tva:metadata:2004"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output encoding="UTF-8" method="xml" omit-xml-declaration="no" version="1.0" />
<xsl:template match="/">
<xsl:variable name="completeTva" select="//tva:TVAMain" />
<xsl:copy-of select ="$completeTva"/>
</xsl:template>
The output of the stylesheet is:
<?xml version="1.0" encoding="utf-8"?>
<tva:TVAMain rightsOwner="FAIRY" xmlns:tva="urn:tva:metadata:2004" xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0" xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
What I require is:
<?xml version="1.0" encoding="utf-8"?>
<tva:TVAMain rightsOwner="FAIRY" xmlns:tva="urn:tva:metadata:2004">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
Any help would be greatly appreciated.
:)
This transformation (Sorry, this is a bug in the SO code-formatter!):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tva="urn:tva:metadata:2004"
xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0"
xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vtoDiscard" select=
"document('')
/*/namespace::*[name()='ns0' or name()='mco']"/>
<xsl:template match="tva:*">
<xsl:element name="{name()}"
namespace="urn:tva:metadata:2004">
<xsl:copy-of select="namespace::*[not(. = $vtoDiscard)]"/>
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="text()[not(ancestor::BodyMessage)]"/>
</xsl:stylesheet>
when applied on the provided XML document:
<ns0:Wrapper
xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0"
xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0">
<TaskName>SomeTaskName</TaskName>
<TaskStatus>Start</TaskStatus>
<Id>Y/0070/0010</Id>
<BodyMessage>
<tva:TVAMain rightsOwner="FAIRY"
xmlns:tva="urn:tva:metadata:2004">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
</tva:TVAMain>
</BodyMessage>
</ns0:Wrapper>
produces the wanted, correct result:
<tva:TVAMain xmlns:tva="urn:tva:metadata:2004" rightsOwner="FAIRY">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
</tva:TVAMain>
Explanation:
Both xsl:copy and xsl:copy-of copy an element together with the namespace nodes that belong to it.
The way to strip some namespace nodes off an element is to re-create it using the xsl:element, then to copy from the original element only the wanted namespace nodes.

using bing api xslt

I'm trying to use the Bing Image api, but can't manage to get it working.
I'm trying to transform the result, but the transformation does not return anything useful.
I think this is because I'm doing something wrong with the namespaces, as it is something I find terribly confusing in all xml related languages...
here is an example of what I receive from Bing:
<?xml version="1.0" encoding="utf-8" ?>
<?pageview_candidate?>
<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">
<Query>
<SearchTerms>natalie portman</SearchTerms>
</Query>
<mms:Image xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<mms:Total>644000</mms:Total>
<mms:Offset>0</mms:Offset>
<mms:Results>
<mms:ImageResult>
<mms:Title>Natalie Portman/natalie-portman-83</mms:Title>
<mms:MediaUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.jpg</mms:MediaUrl>
<mms:Url>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:Url><mms:DisplayUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:DisplayUrl>
<mms:Width>1024</mms:Width>
<mms:Height>768</mms:Height>
<mms:FileSize>95173</mms:FileSize>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Thumbnail>
<mms:Url>http://ts1.mm.bing.net/images/thumbnail.aspx?q=809383506038& amp;id=b829ae4c6df8866b6a07325bedca4bbd</mms:Url>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Width>160</mms:Width>
<mms:Height>120</mms:Height>
<mms:FileSize>3838</mms:FileSize>
</mms:Thumbnail></mms:ImageResult>
<mms:ImageResult>
... other ImageResults and closing tags.
here my curent xslt transformation:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<xsl:template match="/">
<list>
<xsl:for-each select="//mms:ImageResult" >
<element>
<image>
<url><xsl:value-of select="/mms:MediaUrl" /></url>
<width><xsl:value-of select="/mms:Width" /></width>
<height><xsl:value-of select="/mms:Height" /></height>
</image>
</element>
</xsl:for-each>
</list>
</xsl:template>
</xsl:stylesheet>
does somebody see my mistake(s)?
because this transform returns me:
<list xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<element>
<image>
<url/>
<width/>
<height/>
</image>
</element>
...
</list>
Shoudnt be...
<url><xsl:value-of select="mms:MediaUrl" /></url>
<width><xsl:value-of select="mms:Width" /></width>
<height><xsl:value-of select="mms:Height" /></height>
?

XPath when a root node and element have different Name Space attributes

I got struck with a problem in VB.Net getting Xpath for an XML element as shown below:
<Parent xmlns:"http://www.sample.com">
<body>
<Child xmlns:"http://www.notsample.com">
<element type="xyz"> ghghghghghg </element>
</Child>
</body>
</Parent>
I need Xpath of the "element" in above XML using VB.Net NameSpace Manager
For the "body" node i have done and its working but i couldnt do the same to "element":
dim bodynode as XMLNode=XML.SelectSingleNode(//ns:body,nsmngr)
where "nsmngr" is the namespacemanger created by me and "ns" is the name space of the "parent node" (which the "body" node inherits) added to the namespace manager as "ns"
Thanks
Kiran
There are two different ways to construct the needed XPath expression:
Define a second namespace binding with NamespaceManager, say ns2: bound to http://www.notsample.com. Then use:
/*/ns:body/ns2:Child/ns2:element
Don't use namespaces at all:
/*/*[name()='body']/*[name()='Child']/*[name()='element']
Given the following xml:
<OuterElem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:test="http://www.w3.org/2001/XMLSchema-instance1" xmlns:test1="http://www.w3.org/2001/XMLSchema-instance1">
<test:parent>
<test1:child1>blabla1</test1:child1>
<test1:child2>blabla2</test1:child2>
<test:child2>blabla3</test:child2>
</test:parent>
<test1:child1>blabla4</test1:child1>
</OuterElem>
the following xslt (xslt 1.0) copies all nodes except "test:parent/test1:child1":
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://www.w3.org/2001/XMLSchema-instance1" xmlns:test1="http://www.w3.org/2001/XMLSchema-instance1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="test:parent/test1:child1"/>
</xsl:stylesheet>
The result will be:
<OuterElem xmlns:test="http://www.w3.org/2001/XMLSchema-instance1" xmlns:test1="http://www.w3.org/2001/XMLSchema-instance1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test:parent>
<test1:child2>blabla2</test1:child2>
<test:child2>blabla3</test:child2>
</test:parent>
<test1:child1>blabla4</test1:child1>
</OuterElem>