Hi,
Please help me in removing the duplicate nodes from the xml.Condition to remove duplicate nodes is quite complicated.
condition 1:In each policy node under policyKey node i have to check policyNbr and PolicyFormCode/code and policyEffectiveDt and policyID
are same in all the policy nodes if they are same i have retain only the policy node which has sourceSystemCd/code='SCBP' present in it.
condition 2:If in the above condition policyNbr and PolicyFormCode/code and policyEffectiveDt and policyID any of this have differnt values i need to display all th policy node.
Input xml:
condition 1:
<?xml version="1.0" encoding="utf-8"?>
<policies>
<!-- policy 1-->
<policy>
<policyKey>
<policyNbr>4567</policyNbr>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>669</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>ARA</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
<!-- second -->
<policy>
<policyKey>
<policyNbr>1234</policyNbr>
<policyID>115774001</policyID>
<policyEffectiveDt>2014-11-11</policyEffectiveDt>
<policyFormCd>
<code>660</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>ARAR</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
<!-- third -->
<policy>
<policyKey>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>660</code>
</policyFormCd>
<policyID>115774001</policyID>
<policyNbr>1234</policyNbr>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>SCBP</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
</policies>
Expexted Output:
<policies>
<!-- policy 1-->
<policy>
<policyKey>
<policyNbr>4567</policyNbr>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>669</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>ARA</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
<!-- third -->
<policy>
<policyKey>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>660</code>
</policyFormCd>
<policyID>115774001</policyID>
<policyNbr>1234</policyNbr>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>SCBP</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
</policies>
Condition 2: display all three policyNodes
<xsl:template match="/policies/policy">
<xsl:choose>
<xsl:when test="./policyKey/policyID">
<xsl:copy-of select='.'/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name='currNumber' select="number(policyKey/policyNbr)"/>
<xsl:variable name="currCode" select="policyKey/policyFormCd/code"/>
<xsl:if test="count(../policy/policyKey[number(policyNbr)=$currNumber and policyFormCd/code=$currCode and policyID]) = 0">
<xsl:copy-of select='.'/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This should work. If the policy has an ID, then copy it. If not and there isn't a matching one with an id then also copy it. (Could be shorter but this should be clear enough). Tested.
Please replace the below part in the above xslt and try...
<xsl:variable name='currNumber' select="translate(policyKey/policyNbr,'0*','')"/>
<xsl:if test="count(../policy/policyKey[translate(policyNbr,'0*','')=$currNumber and policyFormCd/code=$currCode and policyID]) = 0">
Related
I'm familiar with simple muenchian grouping in XSL, but I've encountered a problem, which I honestly don't even know, how to approach it.
So I've got an XML:
<whiskies>
<whisky name="ABC" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="0" date=""/>
<bottle price="" size="" level="70" date=""/>
<bottle price="" size="" level="100" date=""/>
</bottles>
<comments/>
</whisky>
<whisky name="DEF" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="0" date=""/>
<bottle price="" size="" level="100" date=""/>
</bottles>
<comments/>
</whisky>
<whisky name="GHI" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="30" date=""/>
</bottles>
<comments/>
</whisky>
<whiskies>
And the goal is to group the whiskies by levels of a bottle:
So level="0" is considered empty.
Anything from level="1" to level="99" is considered open.
And level="100" is considered unopened.
So the transformed result (will be done in HTML) should look like this:
<h1>Empty</h1>
<ul>
<li>ABC</li>
<li>DEF</li>
</ul>
<h1>Open</h1>
<ul>
<li>ABC</li>
<li>GHI</li>
</ul>
<h1>Unopened</h1>
<ul>
<li>ABC</li>
<li>DEF</li>
</ul>
As you can see, the same whisky can show up in multiple groups, depending on how much bottles there are and how full those bottles are.
The second problem is, that the "Open" group doesn't have an exact value and can be aynthing from 1 to 99.
So yeah, don't really know if this can be solved at all or how to even start on this. Any tips appreciated.
I don't think you want to use Muenchian grouping for this. You would need to define a key that enumerates all values in the range from 1 to 99 - and I believe that would take away any advantage that using a key would otherwise bring.
Since your result has either exactly or at most 3 groups (your question is ambiguous in this respect), you could do simply:
XSLT 1.0
<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"/>
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="whisky[bottles/bottle/#level=0]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="whisky[bottles/bottle[#level>0 and #level < 100]]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="whisky[bottles/bottle/#level=100]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
to get (after fixing the input to be a well-formed XML!):
Result
<?xml version="1.0" encoding="utf-8"?>
<output>
<group status="empty">
<name>ABC</name>
<name>DEF</name>
</group>
<group status="open">
<name>ABC</name>
<name>GHI</name>
</group>
<group status="unopened">
<name>ABC</name>
<name>DEF</name>
</group>
</output>
Make your own adjustment for HTML output.
Added:
Here is an alternative approach using keys (though still not Muenchian grouping) which might be more performant:
<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"/>
<xsl:key name="w" match="whisky" use="bottles/bottle/#level" />
<xsl:key name="w1" match="whisky" use="boolean(bottles/bottle[#level!=0 and #level!=100])" />
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="key('w', 0)">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="key('w1', true())">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="key('w', 100)">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
Or even:
<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"/>
<xsl:key name="bottle" match="bottle" use="ceiling(#level div 99)" />
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="key('bottle', 0)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="key('bottle', 1)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="key('bottle', 2)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
If you did want to use xsl:key, you could create 3 of them with the filter criteria:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:key name="Empty" match="whisky[bottles/bottle/#level=0]" use="#name"/>
<xsl:key name="Open" match="whisky[bottles/bottle/#level[. > 1 and . < 99]]" use="#name"/>
<xsl:key name="Unopened" match="whisky[bottles/bottle/#level=100]" use="#name"/>
<xsl:template match="/">
<xsl:variable name="whiskies" select="/whiskies/whisky/#name"/>
<xsl:for-each select="document('')/xsl:stylesheet/xsl:key/#name">
<xsl:variable name="status" select="."/>
<h1><xsl:value-of select="$status"/></h1>
<ul>
<xsl:for-each select="$whiskies[key($status, .)]">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I need to replace the child node with another node without affecting its sub nodes, I tried matching the child node but was unable to
This is the xml format
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<Header>
<MessageId>{A124-B421-C325-D467}</MessageId>
<Action>find</Action>
</Header>
<Body>
<MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<Run xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Run">
<RunObject class="entity">
<A1>NA</A1>
<A2>False</A2>
<Object class="entity">
<A3>02</A3>
</Object>
<A4>ER</A4>
</RunObject>
</Run>
</MessageParts>
</Body>
</Envelope>
This is the xml format that i require
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<Header>
<MessageId>{A124-B421-C325-D467}</MessageId>
<Action>find</Action>
</Header>
<Body>
<Document>
<Item>
<A1>NA</A1>
<A2>False</A2>
<Base>
<A3>02</A3>
</Base>
<A4>ER</A4>
</Item>
</Document>
</Body>
</Envelope>
This is the code that i through which i tried to change the format
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"
xmlns:r="http://schemas.microsoft.com/dynamics/2008/01/documents/Run"
exclude-result-prefixes="m r">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- move all elements to no namespace -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- rename MessageParts to Document + skip the Run wrapper -->
<xsl:template match="m:MessageParts">
<Document>
<xsl:apply-templates select="r:Run/*"/>
</Document>
</xsl:template>
<!-- rename RunObject to Item + reorder child nodes -->
<xsl:template match="r:RunObject[#class='entity']">
<Item>
<xsl:apply-templates select="r:A1" />
<xsl:apply-templates select="r:A2" />
<xsl:template match="r:Object[#class='entity']>
<Base>
<xsl:apply-templates select="r:A3" />
</Base>
</xsl:Template>
<xsl:apply-templates select="r:A4" />
</Item>
</xsl:template>
</xsl:stylesheet>
I tried matching the Object element but was unable to since i am already matching its parent element that is RunObject
Your mistake is that you cannot define a template inside of a template. So move the <xsl:template match="r:Object[#class='entity']> to the root level and add an <xsl:apply-templates select="r:Object" /> at its place.
The stylesheet could look like this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" xmlns:r="http://schemas.microsoft.com/dynamics/2008/01/documents/Run" exclude-result-prefixes="m r">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- move all elements to no namespace -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- rename MessageParts to Document + skip the Run wrapper -->
<xsl:template match="m:MessageParts">
<Document>
<xsl:apply-templates select="r:Run/*"/>
</Document>
</xsl:template>
<!-- rename RunObject to Item + reorder child nodes -->
<xsl:template match="r:RunObject[#class='entity']">
<Item>
<xsl:apply-templates select="r:A1" />
<xsl:apply-templates select="r:A2" />
<xsl:apply-templates select="r:Object" />
<xsl:apply-templates select="r:A4" />
</Item>
</xsl:template>
<xsl:template match="r:Object[#class='entity']">
<Base>
<xsl:apply-templates select="r:A3" />
</Base>
</xsl:template>
</xsl:stylesheet>
Its output is (nearly) as desired:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Header>
<MessageId>{A124-B421-C325-D467}</MessageId>
<Action>find</Action>
</Header>
<Body>
<Document>
<Item>
<A1>NA</A1>
<A2>False</A2>
<Base>
<A3>02</A3>
</Base>
<A4>ER</A4>
</Item>
</Document>
</Body>
</Envelope>
I added the adjective "nearly", because this result has no namespace, while the sample of your desired outcome is in the namespace
xmlns:m="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"
But because you defined a template that removes the namespaces of all elements, I did ignore that. I simply assume that this part of your question is erroneous.
If you like to change that, restrict the first template and add a general identity template:
<!-- move all elements to no namespace -->
<xsl:template match="*[namespace-uri() != 'http://schemas.microsoft.com/dynamics/2011/01/documents/Message']">
<xsl:element name="{local-name()}">
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
This would make your output containing the root namespace:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<Header>
<MessageId>{A124-B421-C325-D467}</MessageId>
<Action>find</Action>
</Header>
<Body>
<Document xmlns="">
<Item>
<A1>NA</A1>
<A2>False</A2>
<Base>
<A3>02</A3>
</Base>
<A4>ER</A4>
</Item>
</Document>
</Body>
</Envelope>
I have a generic template I've designed with 2 params title and category.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:param name="category" />
<xsl:param name="title" />
<xsl:template name="test-group">
<fo:block>
<xsl:value=of select="$title" />
</fo:block>
<fo:block>
<xsl:value-of select="$category" />
</fo:block>
</xsl:template>
</xsl:stylesheet>
In the parent template I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:include href="templates/generic_template.xsl" />
...
<xsl:call-template name="test-group">
<xsl:with-param name="category" select="'animals'" />
<xsl:with-param name="title" select="'DOGS'" />
</xsl:call-template>
...
</xsl:stylesheet>
However, when the transform completes title and category are blank. I'm using FOP 2.0 so I'm not sure if this is a known shortcoming.
When defining a xsl:template that takes parameters, the parameter names used within the xsl:template should be declared using xls:param elements nested within.
<xsl:template name="test-group">
<xsl:param name="category" />
<xsl:param name="title" />
...
</xsl:template>
The parameters being attached to the xsl:template and not the xsl:stylesheet.
This is similar to when calling the template with xsl:call-template, except you are specifying the values instead using xsl:with-param.
I have two xslt transformations to apply to an xml message.
<?xml version="1.0" encoding="UTF-8"?>
<ListOfBipBoxfldrlbls>
<Batch>
<ListOfFolder>
<Folder>
<FolderNum>Fldr1</FolderNum>
<BoxNumber>Box1</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
<Folder>
<FolderNum>Fldr2</FolderNum>
<BoxNumber>Box1</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
<Folder>
<FolderNum>Fldr3</FolderNum>
<BoxNumber>Box1</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
<Folder>
<FolderNum>Fldr1</FolderNum>
<BoxNumber>Box2</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
<Folder>
<FolderNum>Fldr2</FolderNum>
<BoxNumber>Box2</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
<Folder>
<FolderNum>Fldr3</FolderNum>
<BoxNumber>Box2</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
<Folder>
<FolderNum>Fldr4</FolderNum>
<BoxNumber>Box2</BoxNumber>
<BatchNumber>Batch</BatchNumber>
</Folder>
</ListOfFolder>
<ListOfBox>
<Box>
<BatchNumber>Batch</BatchNumber>
<BoxNumber>Box1</BoxNumber>
</Box>
<Box>
<BatchNumber>Batch</BatchNumber>
<BoxNumber>Box2</BoxNumber>
</Box>
</ListOfBox>
</Batch>
</ListOfBipBoxfldrlbls>
Expected Output :
Box1 Box1 Fldr1 Box1 Fldr2
Box1 Fldr3 Box2 Box2 Fldr1
Box2 Fldr2 Box2 Fldr3 Box2 Fldr4
Here is my xsl
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="phase-1-result">
<xsl:apply-templates select="/" mode="phase-1"/>
</xsl:variable>
<xsl:apply-templates select="$phase-1-result" mode="phase-2"/>
</xsl:template>
<xsl:template match="/" mode="phase-1">
<ListofLabels>
<xsl:for-each select="ListOfBipBoxfldrlbls/Batch/ListOfFolder/Folder">
<Label>
<FolderNum><xsl:value-of select="FolderNum"/></FolderNum>
<Box><xsl:value-of select="BoxNumber"/></Box>
<Batch><xsl:value-of select="BatchNumber"/></Batch>
</Label>
</xsl:for-each>
<xsl:for-each select="ListOfBipBoxfldrlbls/Batch/ListOfBox/Box">
<Label>
<Box><xsl:value-of select="BoxNumber"/></Box>
<Batch><xsl:value-of select="BatchNumber"/></Batch>
</Label>
</xsl:for-each>
</ListofLabels>
</xsl:template>
<xsl:template match="$phase-1-result/ListofLabels/Label" mode="phase-2">
<xsl:variable name="columns" select="3" />
<TABLE border="1">
<xsl:for-each select="$phase-1-result/ListofLabels/Label[position() mod $columns = 1]">
<TR>
<xsl:for-each select=".|following-sibling::$phase-1-result/ListofLabels/Label[position() < $columns]">
<TD>
<xsl:value-of select="." />
</TD>
</xsl:for-each>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
I am trying to restructure the XML in the first pass and store the result in a variable "$phase-1-result" and format in the second pass using the new structure.
The problem is xmlspy is not recognizing the Variable. it is show it as undefined variable and Error: Unexpected token "$phase-1-result/ListofLabels/Label".
Can some one help me identify the Issue.
Thanks in advance.
You only need to use the variable in the initial <xsl:apply-templates select="$phase-1-result" mode="phase-2" />. After that you're "inside" the phase 1 result tree, and the match expressions and further selects don't need to use the variable, they just work within this new context:
<xsl:template match="/">
<xsl:variable name="phase-1-result">
<xsl:apply-templates select="/" mode="phase-1"/>
</xsl:variable>
<TABLE border="1">
<xsl:apply-templates mode="phase-2"
select="($phase-1-result/ListOfLabels/Label)[position() mod 3 = 1]"/>
</TABLE>
</xsl:template>
<!-- phase-1 template as before -->
<xsl:template match="Label" mode="phase-2">
<TR>
<xsl:apply-templates select=".|following-sibling::Label[position() lt 3]"
mode="columns" />
</TR>
</xsl:template>
<xsl:template match="Label" mode="columns">
<TD>
<xsl:value-of select="." />
</TD>
</xsl:template>
Here I'm doing the "select every third Label" logic at the point of applying the phase-2 template, so that template only needs to concern itself with the "me and my next two siblings" bit.
It's no different from declaring a variable containing nodes from the original input tree and then applying templates to those
<xsl:variable name="someNodes" select="/foo/bar | /foo/ping" />
<xsl:apply-templates select="$someNodes" />
<xsl:template match="bar">...</xsl:template>
The template match expressions don't care where the nodes came from, they only care what the nodes look like (is it a bar or a ping).
I am new to XSLT and am having an issue with templates. I have an input xml file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Node>
<PHASE1_TYPE>LEFT,TOP</PHASE1_TYPE>
<PHASE1_HOL>TOK,ZUR,VIN</PHASE1_HOL>
<PHASE2_TYPE>RIGHT,BOTTOM</PHASE2_TYPE>
<PHASE2_HOL>CHF</PHASE2_HOL>
</Node>
My xslt is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template name="tokenize">
<xsl:param name="text" select="."/>
<xsl:param name="separator" select="','"/>
<xsl:choose>
<xsl:when test="not(contains($text, $separator))">
<Holiday>
<xsl:value-of select="normalize-space($text)"/>
</Holiday>
</xsl:when>
<xsl:otherwise>
<Holiday>
<xsl:value-of select="normalize-space(
substring-before($text, $separator))"/>
</Holiday>
<xsl:call-template name="tokenize">
<xsl:with-param name="text"
select="substring-after($text, $separator)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Document>
<xsl:attribute name="xsi:noNamespaceSchemaLocation"
namespace="http://www.w3.org/2001/XMLSchema-instance"
>C:/usr/NONMAR~1/Output.xsd</xsl:attribute>
<xsl:for-each select="Node">
<Deal>
<DealType>
<xsl:value-of select="string(PHASE1_TYPE)"/>
</DealType>
<Holidays>
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="string(PHASE1_HOL)"/>
<xsl:with-param name="separator" select="','"/>
</xsl:call-template>
</Holidays>
</Deal>
<Deal>
<DealType>
<xsl:value-of select="string(PHASE2_TYPE)"/>
</DealType>
<Holidays>
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="string(PHASE2_HOL)"/>
<xsl:with-param name="separator" select="','"/>
</xsl:call-template>
</Holidays>
</Deal>
</xsl:for-each>
</Document>
</xsl:template>
</xsl:stylesheet>
After transformation, my output is:
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:/usr/NONMAR~1/Output.xsd">
<Deal>
<DealType>LEFT,TOP</DealType>
<Holidays>
<Holiday/>
</Holidays>
</Deal>
<Deal>
<DealType>RIGHT,BOTTOM</DealType>
<Holidays>
<Holiday/>
</Holidays>
</Deal>
</Document>
but the expected Output is :
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:/usr/NONMAR~1/Output.xsd">
<Deal>
<DealType>LEFT,TOP</DealType>
<Holidays>
<Holiday>TOK</Holiday>
<Holiday>ZUR</Holiday>
<Holiday>VIN</Holiday>
</Holidays>
</Deal>
<Deal>
<DealType>RIGHT,BOTTOM</DealType>
<Holidays>
<Holiday>CHF</Holiday>
</Holidays>
</Deal>
</Document>
I am using xslt 1.0 and do not want to use third party functions like EXSLT. Again, I am new to XSLT and do not have time right now to learn it. Would really appreciate if someone can tell me why this template is not working properly. Thanks!!
Sorry, but it's impossible to tell, from the information you provide.
On the plus side, you've taken some effort to cut your stylesheet and your sample input down in size and simplify them. That's good; I wish more new Stack Overflow users knew to do that.
On the minus side, the code you provide doesn't produce the output you show from the input you show. First of all, it's not well-formed; the end-tag for an xsl:for-each has gotten left out. And then that for-each, in the template for the document node, uses select="Node", which looks for elements named Node which are children of the document node -- but in your input, the only element child of the document node is named 'Root'. And your tokenization template wraps the individual tokens in item elements, instead of Holiday elements. When the first two slips are fixed, the stylesheet appears to produce the output you desire (modulo the Holiday/item issue):
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"C:/usr/NONMAR~1/Output.xsd">
<Deal>
<DealType>LEFT,TOP</DealType>
<Holidays>
<item>TOK</item>
<item>ZUR</item>
<item>VIN</item>
</Holidays>
</Deal>
<Deal>
<DealType>RIGHT,BOTTOM</DealType>
<Holidays>
<item>CHF</item>
</Holidays>
</Deal>
</Document>