Convert text to xml using XSLT - java

I have a text file as given below:
value1 value2 value3 value4
I want to convert it as following xml using XSLT
<values>
<value>value1</value>
<value>value2</value>
<value>value3</value>
<value>value4</value>
</values>
Thanks in advance.

Assuming XSLT 2.0,
<xsl:template name="main">
<values>
<xsl:for-each select="tokenize(unparsed-text('input.txt'), '\s+')">
<value><xsl:value-of select="."/></value>
</xsl:for-each>
</values>
</xsl:template>

if you can edit your input such that it contains a root element, and a tab character as a separator, such as below:
<root>value1 value2 value3 value4</root>
then, you can apply the following stylesheet:
<?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" omit-xml-declaration="yes"/>
<xsl:template match="/">
<values>
<xsl:call-template name="tokenizeString">
<xsl:with-param name="list" select="."/>
<xsl:with-param name="delimiter" select="' '"/>
</xsl:call-template>
</values>
</xsl:template>
<xsl:template name="tokenizeString">
<!--passed template parameter -->
<xsl:param name="list"/>
<xsl:param name="delimiter"/>
<xsl:choose>
<xsl:when test="contains($list, $delimiter)">
<value>
<!-- get everything in front of the first delimiter -->
<xsl:value-of select="substring-before($list,$delimiter)"/>
</value>
<xsl:call-template name="tokenizeString">
<!-- store anything left in another variable -->
<xsl:with-param name="list" select="substring-after($list,$delimiter)"/>
<xsl:with-param name="delimiter" select="$delimiter"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$list = ''">
<xsl:text/>
</xsl:when>
<xsl:otherwise>
<value>
<xsl:value-of select="$list"/>
</value>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
and produce:
<values>
<value>value1</value>
<value>value2</value>
<value>value3</value>
<value>value4</value>
</values>

Related

Can you declare / generate xslt params dynamically?

I'm trying to generate an xml with the help of xslt templates and I have a tricky thing to do:
I have to generate a certain number of elements that have same tags but with different values inside them. Example of xslt stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="NbOfBatches"/>
<xsl:param name="wholeTag"/>
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<Document xmlns="urn:something" xmlns:file="someUrn>
<FileAppHdr>
<file:NbOfBatches><xsl:value-of select="$NbOfBatches"></xsl:value-of></file:NbOfBatches>
<xsl:call-template name="selects">
<xsl:with-param name="i">1</xsl:with-param>
<xsl:with-param name="count"><xsl:value-of select="$NbOfBatches"/></xsl:with-param>
</xsl:call-template>
</FileAppHdr>
</Document>
</xsl:template>
<xsl:template name="selects">
<xsl:param name="i" />
<xsl:param name="count" />
<xsl:if test="$i <= $count">
<xsl:call-template name="credit">
<xsl:with-param name="param0"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$i <= $count">
<xsl:call-template name="selects">
<xsl:with-param name="i">
<xsl:value-of select="$i + 1"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="credit">
<xsl:param name="param0"/>
<CreditTransfer>
<xsl:value-of select="$param0"/>
</CreditTransfer>
</xsl:template>
</xsl:stylesheet>
In this way, I can use Saxon or JAXP and call .setParameter() for NbOfBatches, it will generate that number of tags. However is there a way to generate / modify name of param0 inside CreditTransfer so that I can loop through data in Java and use .setParameter("param1", value1) and so on ?
Thank you
Rather than trying to pass structured data as a stylesheet parameter, why not generate that structured data as XML and pass that XML document as the source document of the transformation?
As an example, imagine a source XML document with param0 in each Batch:
<Batches>
<Batch>
<param0>it was the best of times</param0>
</Batch>
<Batch>
<param0>it was the worst of times</param0>
</Batch>
<Batch>
<param0>it was the age of wisdom</param0>
</Batch>
<Batch>
<param0>it was the age of foolishness</param0>
</Batch>
</Batches>
with a simplified version of your stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<Document xmlns:file="someUrn">
<FileAppHdr>
<file:NbOfBatches><xsl:value-of select="count(//Batch)"/></file:NbOfBatches>
<xsl:for-each select="//Batch">
<xsl:call-template name="selects">
<xsl:with-param name="param0" select="param0" />
</xsl:call-template>
</xsl:for-each>
</FileAppHdr>
</Document>
</xsl:template>
<xsl:template name="selects">
<xsl:param name="param0" />
<xsl:call-template name="credit">
<xsl:with-param name="param0" select="$param0" />
</xsl:call-template>
</xsl:template>
<xsl:template name="credit">
<xsl:param name="param0"/>
<CreditTransfer>
<xsl:value-of select="$param0"/>
</CreditTransfer>
</xsl:template>
</xsl:stylesheet>
produces this output:
<Document xmlns:file="someUrn">
<FileAppHdr>
<file:NbOfBatches>4</file:NbOfBatches>
<CreditTransfer>it was the best of times</CreditTransfer>
<CreditTransfer>it was the worst of times</CreditTransfer>
<CreditTransfer>it was the age of wisdom</CreditTransfer>
<CreditTransfer>it was the age of foolishness</CreditTransfer>
</FileAppHdr>
</Document>
It's fairly trivial to generate XML from structured data in Java using the Saxon sapling classes. https://www.saxonica.com/html/documentation10/javadoc/net/sf/saxon/sapling/package-summary.html

XSLT1 how to reliably get data out of parent with variable amount of children

I have this really big XML file contains really old animal testing data, each row contains a set of fields, but each field is also again filled with multiple fields. The file uses the sequence of the children to determine the relationship between the actual data.
I need to extract these fields in sequence of 'first all first data fields', then all the second ones, then thirds... ect. but the quantity of data fields is not set in stone for different rows, only in the same row it seems to be consistent.
Its hard to explain, but i added an example document, the first table is the source, the second one is where i want to get to.
I tried something like below to save the node relations but i couldnt get it to work. Id say im only barely past the beginner level of xslt, but due to the current infrastructure requirements i need to get this working in XSLT1;
<xsl:template match="ROW">
<xsl:for-each select="./anamnese/DATA">
<xsl:variable name="depth">
<xsl:number/>
</xsl:variable>
<xsl:value-of select=".//anamnese/DATA[$depth]"/>
<xsl:value-of select=".//diagnose/DATA[$depth]"/>
<xsl:value-of select=".//fichenr./DATA[$depth]"/>
<xsl:value-of select=".//vis/DATA[$depth]"/>
<xsl:value-of select=".//dr._A/DATA[$depth]"/>
</xsl:for-each>
</xsl:template>
An example of the starting table with bogus data. Note how the DATA fields are not reliable in the amount present.
<TABLE>
<ROW MODID="4" RECORDID="1801">
<anamnese>
<DATA>Gevonden in lat decubitus. Dag van huis weggeweest. Vanmorgen nog goed gegeten.</DATA>
</anamnese>
<diagnose>
<DATA/>
</diagnose>
<fichenr.>
<DATA>3607</DATA>
</fichenr.>
<vis>
<DATA>25/08/2017</DATA>
</vis>
<dr._A>
<DATA>EL</DATA>
</dr._A>
</ROW>
<ROW MODID="6" RECORDID="1802">
<anamnese>
<DATA>zeer agressief geworden op korte tijd</DATA>
<DATA/>
<DATA>detartratie nodig. Eerst cardiologisch onderzoek gehad bij Valerie Bavegems. Verslag volgt nog. Drinkt redelijk veel, 500 g afgevallen</DATA>
</anamnese>
<diagnose>
<DATA> euthanasie</DATA>
<DATA/>
<DATA/>
</diagnose>
<fichenr.>
<DATA>3989</DATA>
<DATA>3688</DATA>
<DATA>3608</DATA>
</fichenr.>
<vis>
<DATA>2/11/2017</DATA>
<DATA>6/09/2017</DATA>
<DATA>26/08/2017</DATA>
</vis>
<dr._A>
<DATA>EL</DATA>
<DATA>EL</DATA>
<DATA>MA</DATA>
</dr._A>
</ROW>
<ROW MODID="4" RECORDID="1803">
<anamnese/>
<diagnose/>
<fichenr./>
<vis/>
<dr._A/>
</ROW>
</TABLE>
The desired end product;
<TABLE_B>
<ROW>
<recordId>1801</recordId>
<anamnese>Gevonden in lat decubitus. Vanmorgen nog goed gegeten.</anamnese>
<diagnose></diagnose>
<fichenr.>3607</fichenr.>
<vis>25/08/2017</vis>
<dr._A>EL</dr._A>
</ROW>
<ROW>
<recordId>1802</recordId>
<anamnese>zeer agressief geworden op korte tijd</anamnese>
<diagnose> euthanasie</diagnose>
<fichenr.>3989</fichenr.>
<vis>2/11/2017</vis>
<dr._A></dr._A>
</ROW>
<ROW>
<recordId>1802</recordId>
<anamnese/>
<diagnose></diagnose>
<fichenr.>3688</fichenr.>
<vis>6/09/2017</vis>
<dr._A>EL</dr._A>
</ROW>
<ROW>
<recordId>1802</recordId>
<anamnese>detartratie nodig. Eerst cardiologisch onderzoek gehad bij Valerie Bavegems. Verslag volgt nog. Drinkt redelijk veel, 500 g afgevallen</anamnese>
<diagnose/>
<fichenr.>3608</fichenr.>
<vis>26/08/2017</vis>
<dr._A>MA</dr._A>
</ROW>
<ROW>
<recordId>1803</recordId>
<anamnese/>
<diagnose/>
<fichenr./>
<vis/>
<dr._A/>
</ROW>
</TABLE_B>
How can i reliably extract all the DATA fields with the correct relation intact even if i cannot possibly predict the MAX amount of DATA fields possible in a row? (i've visually seen a row that had 266 :p)
I have assumed that the node anamnese dictates the number of rows to be produced. If it has 3 children, it will produce 3 rows. If it is empty, then no information should follow. I just copied the nodes.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="TABLE">
<TABLE_B>
<xsl:apply-templates/>
</TABLE_B>
</xsl:template>
<xsl:template match="ROW">
<xsl:variable name="ID" select="#RECORDID"/>
<xsl:choose>
<!-- Test for anamnese children.
If there is no child element,
copy the ROW child elements
-->
<xsl:when test="not(anamnese/*)">
<ROW>
<recordId>
<xsl:value-of select="$ID"/>
</recordId>
<xsl:copy-of select="*"/>
</ROW>
</xsl:when>
<xsl:otherwise>
<!-- if there exists anamnese children,
loop through these.-->
<xsl:for-each select="anamnese/*">
<xsl:variable name="pos" select="position()"/>
<ROW>
<recordId>
<xsl:value-of select="$ID"/>
</recordId>
<anamnese>
<xsl:value-of select="."/>
</anamnese>
<!-- loop through the following siblings of anamnese -->
<xsl:for-each select="../following-sibling::*">
<xsl:element name="{local-name()}">
<!-- select nodes with the same position -->
<xsl:value-of select="*[position()=$pos]"/>
</xsl:element>
</xsl:for-each>
</ROW>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
If ROW block structure is static, you can firstly define ROW block structure in separate template with parameters, and then pass its parameters in required loops, see below XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--prepare template for ROW block structure-->
<xsl:template name="row">
<!--pass recordId value-->
<xsl:param name="rec.id"/>
<!--pass ROW position number value-->
<xsl:param name="row.id"/>
<!--pass DATA position number value-->
<xsl:param name="data.id"/>
<!--creating ROW structure-->
<ROW>
<recordId>
<xsl:value-of select="$rec.id"/>
</recordId>
<anamnese>
<xsl:value-of select="//ROW[$row.id]/anamnese/DATA[$data.id]"/>
</anamnese>
<diagnose>
<xsl:value-of select="//ROW[$row.id]/diagnose/DATA[$data.id]"/>
</diagnose>
<fichenr.>
<xsl:value-of select="//ROW[$row.id]/fichenr./DATA[$data.id]"/>
</fichenr.>
<vis>
<xsl:value-of select="//ROW[$row.id]/vis/DATA[$data.id]"/>
</vis>
<dr._A>
<xsl:value-of select="//ROW[$row.id]/dr._A/DATA[$data.id]"/>
</dr._A>
</ROW>
</xsl:template>
<xsl:template match="/">
<!--desired name of root node-->
<TABLE_B>
<xsl:for-each select="//anamnese">
<!--get recordId number-->
<xsl:variable name="var.rec.id" select="../#RECORDID"/>
<!--get row position number-->
<xsl:variable name="var.row.id" select="position()"/>
<xsl:choose>
<!--check if DATA block exists-->
<xsl:when test="DATA">
<xsl:for-each select="DATA">
<xsl:call-template name="row">
<xsl:with-param name="rec.id" select="$var.rec.id"/>
<xsl:with-param name="row.id" select="$var.row.id"/>
<xsl:with-param name="data.id" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<!--proceed if DATA block does not exist-->
<xsl:otherwise>
<xsl:call-template name="row">
<xsl:with-param name="rec.id" select="$var.rec.id"/>
<xsl:with-param name="row.id" select="$var.row.id"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</TABLE_B>
</xsl:template>
</xsl:stylesheet>
Then try it with your input XML and result will be as desired:
<?xml version="1.0" encoding="UTF-8"?>
<TABLE_B>
<ROW>
<recordId>1801</recordId>
<anamnese>Gevonden in lat decubitus. Dag van huis weggeweest. Vanmorgen nog goed gegeten.</anamnese>
<diagnose/>
<fichenr.>3607</fichenr.>
<vis>25/08/2017</vis>
<dr._A>EL</dr._A>
</ROW>
<ROW>
<recordId>1802</recordId>
<anamnese>zeer agressief geworden op korte tijd</anamnese>
<diagnose> euthanasie</diagnose>
<fichenr.>3989</fichenr.>
<vis>2/11/2017</vis>
<dr._A>EL</dr._A>
</ROW>
<ROW>
<recordId>1802</recordId>
<anamnese/>
<diagnose/>
<fichenr.>3688</fichenr.>
<vis>6/09/2017</vis>
<dr._A>EL</dr._A>
</ROW>
<ROW>
<recordId>1802</recordId>
<anamnese>detartratie nodig. Eerst cardiologisch onderzoek gehad bij Valerie Bavegems. Verslag volgt nog. Drinkt redelijk veel, 500 g afgevallen</anamnese>
<diagnose/>
<fichenr.>3608</fichenr.>
<vis>26/08/2017</vis>
<dr._A>MA</dr._A>
</ROW>
<ROW>
<recordId>1803</recordId>
<anamnese/>
<diagnose/>
<fichenr./>
<vis/>
<dr._A/>
</ROW>
</TABLE_B>
This may help you.
<xsl:template match="TABLE">
<xsl:element name="TABLE_B">
<xsl:apply-templates select="ROW"/>
</xsl:element>
</xsl:template>
<xsl:template match="ROW">
<xsl:apply-templates select="anamnese">
<xsl:with-param name="RECORDID" select="#RECORDID"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="anamnese">
<xsl:param name="RECORDID"/>
<xsl:apply-templates select="DATA">
<xsl:with-param name="RECORDID" select="$RECORDID"/>
</xsl:apply-templates>
<xsl:if test="not(DATA)">
<xsl:element name="ROW">
<xsl:element name="recordId">
<xsl:value-of select="$RECORDID"/>
</xsl:element>
<xsl:element name="anamnese">
<xsl:value-of select="text()"/>
</xsl:element>
<xsl:apply-templates select="following-sibling::*"/>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="DATA">
<xsl:param name="RECORDID"/>
<xsl:variable name="position" select="position()"/>
<xsl:element name="ROW">
<xsl:element name="recordId">
<xsl:value-of select="$RECORDID"/>
</xsl:element>
<xsl:element name="anamnese">
<xsl:value-of select="text()"/>
</xsl:element>
<xsl:element name="diagnose">
<xsl:value-of select="../../diagnose/DATA[$position]"/>
</xsl:element>
<xsl:element name="fichenr.">
<xsl:value-of select="../../fichenr./DATA[$position]"/>
</xsl:element>
<xsl:element name="vis">
<xsl:value-of select="../../vis/DATA[$position]"/>
</xsl:element>
<xsl:element name="dr._A">
<xsl:value-of select="../../dr._A/DATA[$position]"/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>

How to Read Java List Object in XSL

I am having a Java Object which is ArrayList and i have added it in response of service which is in XML format as below,
<root>
<SubRoot>
<type>A</type>
<mand>Y</mand>
<Section>B</Section>
</SubRoot>
<SubRoot>
<type>A</type>
<mand>Y</mand>
<Section>A</Section>
</SubRoot>
</root>
I am trying to use the some value from above xml for condition.On basis of true condition i will call some template for my purpose.
I am calling my xsl template as below,
<xsl:choose>
<xsl:when test="(/root/SubRoot[Section = 'A'])">
//Call some template
</xsl:when>
<xsl:otherwise>
//some template
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="(/root/SubRoot[Section = 'B'])">
//call some template
</xsl:when>
<xsl:otherwise>
//some template
</xsl:otherwise>
</xsl:choose>
Each time my first when will get executed its not coming inside the second when condition.
Could you please help me how the both condition will get executed?is it right approach in terms of performance?
Any Suggestion approach must be appreciated.
Try this,
XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://locomotive/bypass/docx">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:strip-space elements="*" />
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="SubRoot">
<xsl:choose>
<xsl:when test="Section = 'A'">
<!-- your logic for A -->
<A></A>
</xsl:when>
<xsl:otherwise>
<!-- your logic for B -->
<B></B>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
XML
<root>
<SubRoot>
<type>A</type>
<mand>Y</mand>
<Section>B</Section>
</SubRoot>
<SubRoot>
<type>A</type>
<mand>Y</mand>
<Section>A</Section>
</SubRoot>
Demo link : http://xsltransform.net/ejivdHb/15

Why does this xslt transformation replace all occurences?

Using http://xslt.online-toolz.com/tools/xslt-transformation.php
.xml
<?xml version="1.0"?>
<my:project xmlns:my="http://myns">
<my:properties>
<my:property>
<my:name>customerId</my:name>
<my:value>1</my:value>
</my:property>
<my:property>
<my:name>userId</my:name>
<my:value>20</my:value>
</my:property>
</my:properties>
</my:project>
I now want to look for the name customerId and want to replace the value.
It almost works, but it replaces ALL values in the document. What am I doing wrong to just replace the value where the name mached?
.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://myns" xmlns:saxon="http://saxon.sf.net">
<xsl:param name="name" select="'customerId'"/>
<xsl:param name="value" select="'0'"/>
<xsl:template match="node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/my:properties/my:property/my:value/text()" >
<xsl:choose>
<xsl:when test="/*/my:properties/my:property/my:name = $name">
<xsl:value-of select="$value"/>
</xsl:when>
<xsl:otherwise><xsl:copy-of select="saxon:parse(.)" /></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The test for /*/my:properties/my:property/my:name = $name always succeed because it uses an absolute path, and so the result is independent of the surrounding template context. A test with a relative xpath should work.
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://myns" xmlns:saxon="http://saxon.sf.net">
<xsl:param name="name" select="'customerId'"/>
<xsl:param name="value" select="'0'"/>
<xsl:template match="node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/my:properties/my:property/my:value/text()" >
<xsl:choose>
<xsl:when test="../../my:name = $name">
<xsl:value-of select="$value"/>
</xsl:when>
<xsl:otherwise>otherwise</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
XML:
<my:project xmlns:my="http://myns">
<my:properties>
<my:property>
<my:name>customerId</my:name>
<my:value>1</my:value>
</my:property>
<my:property>
<my:name>userId</my:name>
<my:value>20</my:value>
</my:property>
</my:properties>
</my:project>
Result of saxonb-xslt -s:test.xml -xsl:test.xsl
<my:project xmlns:my="http://myns">
<my:properties>
<my:property>
<my:name>customerId</my:name>
<my:value>0</my:value>
</my:property>
<my:property>
<my:name>userId</my:name>
<my:value>otherwise</my:value>
</my:property>
</my:properties>
</my:project>

XSLT Apply Template for Specific list of value

I am beginner in XSLT.
My Source XML is as below
<Options>
<Option>
<Data>Data1</Data>
<Type>A</Type>
</Option>
<Option>
<Data>Data2</Data>
<Type>B</Type>
</Option>
<Option>
<Data>Data3</Data>
<Type>C</Type>
</Option>
<Option>
<Data>Data4</Data>
<Type>D</Type>
</Option>
...
</Options>
I have parameter which is used to filter the result from above method and it is as below
<xsl:param name="filterType" select="'A,C'"/>
The output should be as below:
<Result>
<Data Type="A">Data1<Data>
<Data Type="C">Data3<Data>
</Result>
Below is the XSLT i have created:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="filterType" select="'A,C'"/>
<xsl:template match="Options">
<xsl:element name="Result">
<xsl:apply-templates select="Option"/>
</xsl:element>
</xsl:template?
<xsl:template match="Option">
<xsl:element name="Data">
<xsl:attribute name="Type">
<xsl:value-of select="Type"/>
</xsl:attribute>
<xsl:value-of select="Data"/>
</xsl:element>
</xsl:template?
</xsl:stylesheet>
While applying template for 'Option' tag i need to use filterType.
How can i do that? Please Help.
I think you simply want
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="filterType" select="'A,C'"/>
<xsl:variable name="filter" select="concat(',', $filterType, ',')"/>
<xsl:template match="Options">
<Result>
<xsl:apply-templates select="Option[contains($filter, concat(',', Type, ','))]"/>
</Result>
</xsl:template>
<xsl:template match="Option">
<Data Type="{Type}">
<xsl:value-of select="Data"/>
</Data>
</xsl:template>
</xsl:stylesheet>

Categories

Resources