How to write XSLT for Converting XML to JSON? - xslt

I have the following XML File as input and want an JSON output using XSLT mapping. How can I design my XSLT file?
XML Input:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SyncItemMaster versionID="2.14.0" releaseID="9.2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.14.0/InforOAGIS/BODs/SyncItemMaster.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schema.infor.com/InforOAGIS/2">
<ApplicationArea>
<Sender>
<LogicalID>lid://infor.ln.ln_1100</LogicalID>
<ComponentID>erp</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2020-06-16T11:00:16Z</CreationDateTime>
<BODID>infor-nid:infor:1100::11064973:?ItemMaster&verb=Sync</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor</TenantID>
<AccountingEntityID>1100</AccountingEntityID>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Change"/>
</ActionCriteria>
</Sync>
<ItemMaster>
<ItemMasterHeader>
<ItemID>
<ID variationID="4241287" lid="lid://infor.ln.ln_1100" accountingEntity="1100">11064973</ID>
</ItemID>
<DisplayID>11064973</DisplayID>
<GTIN/>
<ServiceIndicator>false</ServiceIndicator>
<Description>H3BO3 4% mit Sher Indikator</Description>
<Description languageID="de_DE">H3BO3 4% mit Sher Indikator</Description>
<Description languageID="fr_FR">H3BO3 4% mit Sher Indikator</Description>
<Description languageID="it_IT">H3BO3 4% mit Sher Indikator</Description>
<Description languageID="nl_NL">H3BO3 4% mit Sher Indikator</Description>
<Description languageID="en_US">H3BO3 4% mit Sher Indikator</Description>
<Note/>
</ItemMasterHeader>
</ItemMaster>
</DataArea>
</SyncItemMaster>
Expected JSON Output:
{
"description":[
{
"languageID":"ge_GE",
"text":"H3BO3 4% mit Sher Indikator"
},
{
"languageID":"de_DE",
"text":"H3BO3 4% mit Sher Indikator"
},
{
"languageID":"fr_FR",
"text":"H3BO3 4% mit Sher Indikator"
},
{
"languageID":"it_IT",
"text":"H3BO3 4% mit Sher Indikator"
},
{
"languageID":"nl_NL",
"text":"H3BO3 4% mit Sher Indikator"
},
{
"languageID":"en_US",
"text":"H3BO3 4% mit Sher Indikator"
}
]
}

In general, in XSLT 3 you have two options, create the JSON as the corresponding XPath 3.1 maps and arrays (https://xsltfiddle.liberty-development.net/pNmCzsG):
<?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"
xpath-default-namespace="http://schema.infor.com/InforOAGIS/2"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="json" indent="yes"/>
<xsl:template match="/">
<xsl:sequence
select="map {
'description' : array {
//Description !
map {
'languageID' : (data(#languageID), 'ge_GE') => head(),
'text' : data()
}
}
}"/>
</xsl:template>
</xsl:stylesheet>
or transform the XML input to the XML input format the xml-to-json functions expects (see intermediary result of
<?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"
xpath-default-namespace="http://schema.infor.com/InforOAGIS/2"
xmlns="http://www.w3.org/2005/xpath-functions"
expand-text="yes"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<map>
<xsl:where-populated>
<array key="description">
<xsl:apply-templates select="//Description"/>
</array>
</xsl:where-populated>
</map>
</xsl:template>
<xsl:template match="Description[not(#languageID)]">
<map>
<string key="languageID">ge_GE</string>
<string key="text">{.}</string>
</map>
</xsl:template>
<xsl:template match="Description">
<map>
<string key="languageID">{#languageID}</string>
<string key="text">{.}</string>
</map>
</xsl:template>
</xsl:stylesheet>
) and then use that function xml-to-json (https://xsltfiddle.liberty-development.net/pNmCzsG/1):
<?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"
xpath-default-namespace="http://schema.infor.com/InforOAGIS/2"
xmlns="http://www.w3.org/2005/xpath-functions"
expand-text="yes"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="json-xml">
<map>
<xsl:where-populated>
<array key="description">
<xsl:apply-templates select="//Description"/>
</array>
</xsl:where-populated>
</map>
</xsl:variable>
<xsl:value-of select="xml-to-json($json-xml, map { 'indent' : true() })"/>
</xsl:template>
<xsl:template match="Description[not(#languageID)]">
<map>
<string key="languageID">ge_GE</string>
<string key="text">{.}</string>
</map>
</xsl:template>
<xsl:template match="Description">
<map>
<string key="languageID">{#languageID}</string>
<string key="text">{.}</string>
</map>
</xsl:template>
</xsl:stylesheet>
The first attempt shown above does not define the order of the JSON property output unless you use a Saxon specific extension attribute. With the second suggestion you could define the order.

Related

XSLT: Convert JSON to XML, then transform, in one XSLT

I'm trying to convert JSON to a specific XML format, all in one XSLT. (It doesn't have to be in one step, but, you know,...)
I can convert the JSON to generic XML from here: How to use XPath/XSLT fn:json-to-xml
Converting the resultant generic XML to the XML I want is then simple.
But I can't work out how to combine the XSLTs so I can do it in one step, do JSON-to-XML and then the XML transformation. I've tried with variables, include, import, but can't get it to work.
I suspect it's straightforward! It needs to be in (just) XSLT.
So, from the question linked to above, I start with JSON (in XML tags)
<root>
<data>{
"desc" : "Distances between several cities, in kilometers.",
"updated" : "2014-02-04T18:50:45",
"uptodate": true,
"author" : null,
"cities" : {
"Brussels": [
{"to": "London", "distance": 322},
{"to": "Paris", "distance": 265},
{"to": "Amsterdam", "distance": 173}
],...
and transform to
<map xmlns="http://www.w3.org/2005/xpath-functions">
<string key="desc">Distances between several cities, in kilometers.</string>
<string key="updated">2014-02-04T18:50:45</string>
<boolean key="uptodate">true</boolean>
<null key="author"/>
<map key="cities">
<array key="Brussels">
<map>
<string key="to">London</string>
<number key="distance">322</number>
</map>
<map>
<string key="to">Paris</string>
<number key="distance">265</number>
</map>...
using
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math" version="3.0">
<xsl:output indent="yes"/>
<xsl:template match="data">
<xsl:copy-of select="json-to-xml(.)"/>
</xsl:template>
</xsl:stylesheet>
Now I can apply this stylesheet to the 'intermediate' XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://www.w3.org/2005/xpath-functions">
<xsl:output indent="yes"/>
<xsl:template match="/">
<Distances>
<xsl:for-each select="f:map/f:map/f:array">
<Start>
<StartPoint><xsl:value-of select="#key"/></StartPoint>
<xsl:for-each select="f:map">
<Distance>
<xsl:attribute name="end"><xsl:value-of select="f:string"/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="f:number"/></xsl:attribute>
</Distance>
</xsl:for-each>
</Start>
</xsl:for-each>
</Distances>
</xsl:template>
</xsl:stylesheet>
and get my desired structure:
<?xml version="1.0" encoding="UTF-8"?>
<Distances xmlns:f="http://www.w3.org/2005/xpath-functions">
<Start>
<StartPoint>Brussels</StartPoint>
<Distance end="London" value="322"/>
<Distance end="Paris" value="265"/>
<Distance end="Amsterdam" value="173"/>
</Start>...
So, is it possible to combine the JSON-to-XML and the XML transformation XSLs in one?
I am guessing you want to do:
XSLT 3.0
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="f">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/root">
<Distances>
<xsl:for-each select="json-to-xml(data)/f:map/f:map/f:array">
<Start>
<StartPoint>
<xsl:value-of select="#key"/>
</StartPoint>
<xsl:for-each select="f:map">
<Distance end="{f:string}" value="{f:number}"/>
</xsl:for-each>
</Start>
</xsl:for-each>
</Distances>
</xsl:template>
</xsl:stylesheet>
Untested, because no code suitable for testing was provided.
To do it the way you were proposing, you can do
<xsl:template match="data">
<xsl:apply-templates select="json-to-xml(.)"/>
</xsl:template>
and then add template rules to transform the generic XML produced by json-to-xml() to your application-specific XML.
But I think the approach suggested by #michael.hor257k is probably better.

XSLT 1.0: key not working in selecting nodes

I have an XML and an XSLT that gives a current output. It uses a "key" but I am not getting the expected output
Source XML:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Receivers>
<ReceiverRule>
<Condition>
<Value>Condition 1</Value>
</Condition>
<Receiver>
<party>party1</party>
<system>SYS1</system>
</Receiver>
</ReceiverRule>
<ReceiverRule>
<Condition>
<Value>Condition 2</Value>
</Condition>
<Receiver>
<party>party2</party>
<system>SYS2</system>
</Receiver>
</ReceiverRule>
</Receivers>
<ReceiverInterfaces>
<Receiver>
<party>party1</party>
<system>SYS1</system>
</Receiver>
<ReceiverInterfaceRule>
<Rule>Rule 1 sytem 1</Rule>
</ReceiverInterfaceRule>
<ReceiverInterfaceRule>
<Rule>Rule 2 system 1</Rule>
</ReceiverInterfaceRule>
</ReceiverInterfaces>
<ReceiverInterfaces>
<Receiver>
<party>party2</party>
<system>SYS2</system>
</Receiver>
<ReceiverInterfaceRule>
<Rule>Rule 1 system 2</Rule>
</ReceiverInterfaceRule>
<ReceiverInterfaceRule>
<Rule>Rule 2 system 2</Rule>
</ReceiverInterfaceRule>
</ReceiverInterfaces>
</Root>
My XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:key name="Receiver" match="ReceiverRule/Receiver" use="concat(party,system)"/>
<xsl:template match="Root">
<ReceiverList>
<xsl:apply-templates select="Receivers/ReceiverRule"/>
</ReceiverList>
</xsl:template>
<xsl:template match="ReceiverRule">
<Receiver>
<Name>
<xsl:value-of select="concat(Receiver/party, ' ' ,Receiver/system)"/>
</Name>
<Condition>
<xsl:value-of select="Condition/Value"/>
</Condition>
<xsl:apply-templates select="ancestor::Root/ReceiverInterfaces
[Receiver/child::* = key('Receiver',Root/Receivers/ReceiverRule/Receiver)]"/>
</Receiver>
</xsl:template>
<xsl:template match="ReceiverInterfaces">
<xsl:apply-templates select="ReceiverInterfaceRule"/>
</xsl:template>
<xsl:template match="ReceiverInterfaceRule">
<Rule>
<xsl:value-of select="Rule"/>
</Rule>
</xsl:template>
</xsl:stylesheet>
produces this XML output:
<?xml version="1.0" encoding="UTF-8"?>
<ReceiverList>
<Receiver>
<Name>party1 SYS1</Name>
<Condition>Condition 1</Condition>
</Receiver>
<Receiver>
<Name>party2 SYS2</Name>
<Condition>Condition 2</Condition>
</Receiver>
</ReceiverList>
But I am expecting this output:
<?xml version="1.0" encoding="UTF-8"?>
<ReceiverList>
<Receiver>
<Name>party1 SYS1</Name>
<Condition>Condition 1</Condition>
<Rule>Rule 1 sytem 1</Rule>
<Rule>Rule 2 system 1</Rule>
</Receiver>
<Receiver>
<Name>party2 SYS2</Name>
<Condition>Condition 2</Condition>
<Rule>Rule 1 system 2</Rule>
<Rule>Rule 2 system 2</Rule>
</Receiver>
</ReceiverList>
somehow my key is not recognized.
I think instead of
<xsl:apply-templates select="ancestor::Root/ReceiverInterfaces
[Receiver/child::* = key('Receiver',Root/Receivers/ReceiverRule/Receiver)]"/>
all you want is
<xsl:apply-templates select="key('Receiver', concat(Receiver/party, Receiver/system))/ReceiverInterfaceRule"/>
with the key as
<xsl:key name="Receiver" match="ReceiverInterfaces" use="concat(Receiver/party, Receiver/system)"/>

Match node in JSON input

I have the following code, which I am using to transform a JSON file to another JSON.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:fcn="http://www.re.com/2018/local-functions" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs fn fcn exsl" version="3.0">
<xsl:param as="xs:string" name="json">[{
"results": [
{
"id": "5b33c2e8-8ab2-4314-82bf-e41a007c076f",
"profileId": "0f53bfe5-4ef3-4424-9ad2-ad8181007e22"
}
],
"_embedded": {
},
"paging": {
"pageNumber": 1,
"pageSize": 10,
"totalCount": 4
}
}]</xsl:param>
<xsl:output indent="yes" method="text" />
<xsl:template match="/" name="xsl:initial-template">
<xsl:variable name="input-as-xml" select="json-to-xml($json)" />
<xsl:variable name="transformed-xml">
<array xmlns="http://www.w3.org/2005/xpath-functions">
<xsl:for-each select="fn:array[#key = 'results']/*">
<map>
<xsl:if test="*[#key = 'id'] != ''">
<string key="id">
<xsl:value-of select="fn:string[#key = 'id']" />
</string>
</xsl:if>
</map>
</xsl:for-each>
</array>
</xsl:variable>
<xsl:value-of select="xml-to-json($transformed-xml, map {'indent': true()})" />
</xsl:template>
</xsl:stylesheet>
I am trying to match the results object, but when I apply the stylesheet, I am getting an empty JSON output.
Some help with matching the results object correctly would be appreciated.
The input-as-xml:
<?xml version="1.0" encoding="UTF-8"?>
<array xmlns="http://www.w3.org/2005/xpath-functions">
<map>
<array key="results">
<map>
<string key="id">5b33c2e8-8ab2-4314-82bf-e41a007c076f</string>
<string key="profileId">0f53bfe5-4ef3-4424-9ad2-ad8181007e22</string>
</map>
</array>
<map key="_embedded"/>
<map key="paging">
<number key="pageNumber">1</number>
<number key="pageSize">10</number>
<number key="totalCount">4</number>
</map>
</map>
</array>
For starters, I think the xsl:for-each should be something like <xsl:for-each select="$input-as-xml/fn:array[#key = 'results']/*">, so you're selecting within the right context.
But I don't think that's quite enough: The XML that comes from the conversion will contain an <fn:array> whose first child will be an <fn:map> which will have an entry of the form <fn:array key="results">, so you need to select deeper into the structure.
It's probably a good idea to print out the value of $input-as-xml (in indented form) for ease of diagnostics.

Modify node text within xsl copy-of

I have a xml document which looks like
<!-- language: lang-xml -->
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="fst" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<AccountServer e-dtype="int">3</AccountServer>
</Header>
<Response>
<ResponseList e-dtype="list">
<Response>
<RequestId e-dtype="string">ServiceOrderGetRef</RequestId>
<RequestObjName e-dtype="string">ServiceOrder</RequestObjName>
<ServiceOrder>
<CreateDt e-dtype="dateTime">2014-03-01 00:00:00</CreateDt>
<CreateWho e-dtype="string">vc</CreateWho>
<WorkflowStartDt e-dtype="dateTime">2014-04-01 00:00:00</WorkflowStartDt>
</ServiceOrder>
</Response>
<Response>
<ComponentList e-dtype="list"/>
<Count e-dtype="int">0</Count>
<RequestId e-dtype="string">ComponentFindRef</RequestId>
<RequestObjName e-dtype="string">Component</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
<Response>
<Count e-dtype="int">0</Count>
<CustomerContractList e-dtype="list"/>
<RequestId e-dtype="string">CustomerContractRef</RequestId>
<RequestObjName e-dtype="string">CustomerContract</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
<Response>
<Count e-dtype="int">0</Count>
<ProductList e-dtype="list"/>
<RequestId e-dtype="string">ProductRef</RequestId>
<RequestObjName e-dtype="string">Product</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
<Response>
<Count e-dtype="int">0</Count>
<NrcList e-dtype="list"/>
<RequestId e-dtype="string">NrcFindRef</RequestId>
<RequestObjName e-dtype="string">Nrc</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
</ResponseList>
</Response>
</Request>
I am using copy-of function to copy node ServiceOrder within another xml document
I want to modify text of node WorkFlowStartDt and CreateDt and then do a copy-of. How can I do this?
My copied serviceorder node should look like this after modifing text. Below is the result xml
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess>
<Fetch e-dtype="boolean">true</Fetch>
<Order>
<AccountInternalId e-dtype="int">12345</AccountInternalId>
<Key>
<OrderId e-dtype="numeric">12345678</OrderId>
</Key>
</Order>
<ServiceOrderList e-dtype="list">
<ServiceOrder xmlns="fst" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
<CreateDt e-dtype="dateTime">2014-03-02 00:00:00</CreateDt>
<CreateWho e-dtype="string">vc</CreateWho>
<WorkflowStartDt e-dtype="dateTime">2014-05-01 00:00:00</WorkflowStartDt>
</ServiceOrder>
</ServiceOrderList>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</RequestList>
</CustomerUdtRequest>
</Request>
Below is my xslt processor file
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess> <Order> <AccountInternalId e-dtype="int">
<xsl:value-of
select="/Request/Response/ResponseList/Response/ServiceOrder/AccountInternalId"/>
</AccountInternalId> <Key> <OrderId e-dtype="numeric"> <xsl:value-of select="/Request/Response/ResponseList/Response/ServiceOrder/OrderId"/>
</OrderId>
</Key>
</Order>
<ServiceOrderList e-dtype="list">
<xsl:copy-of select="/Request/Response/ResponseList/Response/ServiceOrder"/>
</ServiceOrderList>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</xsl:if>
</RequestList>
</CustomerUdtRequest>
</Request>
</xsl:template>
</xsl:stylesheet>
I want to modify text of node WorkFlowStartDt and CreateDt and then do
a copy-of.
That would be an unnecessary complication. You can modify nodes while you add them to the output tree.
Since you essentially want to copy everything "as is" except two nodes, it would be best to start with an identity transform template, then add an "exception" template for the two specific nodes that need modifying (one template for both, since the modification is identical).:
<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"/>
<!-- identity transformation -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="CreateDt | WorkFlowStartDt">
<xsl:copy>
<xsl:value-of select="concat('**', ., '**')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Added:
In response to the edited question, try this stylesheet:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="fst"
exclude-result-prefixes="ns">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess>
<Order>
<AccountInternalId e-dtype="int">
<!-- THIS DOESN'T POINT TO ANY EXISTING NODE!! -->
<xsl:value-of select="ns:Request/ns:Response/ns:ResponseList/ns:Response/ns:ServiceOrder/ns:AccountInternalId"/>
</AccountInternalId>
<Key>
<OrderId e-dtype="numeric">
<!-- THIS DOESN'T POINT TO ANY EXISTING NODE!! -->
<xsl:value-of select="ns:Request/ns:Response/ns:ResponseList/ns:Response/ns:ServiceOrder/ns:OrderId"/>
</OrderId>
</Key>
</Order>
<xsl:apply-templates select="ns:Request/ns:Response/ns:ResponseList/ns:Response/ns:ServiceOrder"/>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</RequestList>
</CustomerUdtRequest>
</Request>
</xsl:template>
<xsl:template match="ns:ServiceOrder">
<xsl:copy>
<xsl:copy-of select="ns:CreateWho"/>
<xsl:apply-templates select="ns:CreateDt | ns:WorkflowStartDt"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns:CreateDt | ns:WorkflowStartDt">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:value-of select="concat('**', ., '**')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When applied to your input (minus the illegal opening comment), the following result is obtained:
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess>
<Order>
<AccountInternalId e-dtype="int"/>
<Key>
<OrderId e-dtype="numeric"/>
</Key>
</Order>
<ServiceOrder xmlns="fst" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CreateWho e-dtype="string">vc</CreateWho>
<CreateDt e-dtype="dateTime">**2014-03-01 00:00:00**</CreateDt>
<WorkflowStartDt e-dtype="dateTime">**2014-04-01 00:00:00**</WorkflowStartDt>
</ServiceOrder>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</RequestList>
</CustomerUdtRequest>
</Request>

Looping in XSLT

I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="sample.xsl" type="text/xsl"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel
xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal">
<title cf:type="text">The Hindu - Front Page</title>
<link>http://www.hindu.com/</link>
<description cf:type="text">The Internet edition of The Hindu,
India's national newspaper</description>
<image>
<url>http://www.hindu.com/hindu/hindux.gif</url>
<title>hindu.com</title>
<link>http://www.hindu.com/</link>
</image>
<item>
<title cf:type="text"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
>ISRO spectrum deal under review: Centre</title>
</item>
<item>
<title cf:type="text"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
>Response from Devas</title>
</item>
</channel>
</rss>
The rss/channel/item can be of any count(in the current case it's count is 2). I need to display the Titles as a Marquee one after the other as follows
ISRO spectrum deal under review: Centre, Response from Devas,....,....
How can I accomplish this in XSLT? kindly advice
Thanks
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal"
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005"
xmlns:dc="http://purl.org/dc/elements/1.1/"
exclude-result-prefixes="cfi cf dc">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/*">
<div id="marquee">
<xsl:apply-templates select="channel/item/title"/>
</div>
</xsl:template>
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">, </xsl:if>
</xsl:template>
</xsl:stylesheet>
Result against your sample:
<div id="marquee">ISRO spectrum deal under review: Centre, Response from Devas</div>
In addition to #Flack correct answer, in XSLT 2.0 xsl:value-of instruction preserves sequence. So, this stylesheet:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div id="marquee">
<xsl:value-of select="rss/channel/item/title"
separator=", "/>
</div>
</xsl:template>
</xsl:stylesheet>
Also outputs:
<div id="marquee"
>ISRO spectrum deal under review: Centre, Response from Devas</div>