Page 1 of 2

XSPEC and XSLT issue

Posted: Wed Apr 15, 2015 7:25 pm
by tsm21
Hi,

We have a XSPEC file which tests an XSL file (which compares two XML files and display differences in an output file).

The XSL files contains global parameters, so have passed values to the XSL file through global parameters in XSPEC file.

One input is passed through a parameter say p1 and other through <x:context>.

Problem is that when i try to run the XSPEC file an error is generated saying that "context node not found" and this is due to the line written in XSL file to read input xml file.

<xsl:variable name="s.root" select="/">

XSPEC is unable to read the "/" in XSL file, So one of the inputs is not considered in XSL file.

Is there any way to fix this issue?

Thanks for your help,
Sai

Re: XSPEC and XSLT issue

Posted: Thu Apr 16, 2015 10:17 am
by Radu
Hi,

Could you try to create some small sample files to demonstrate the problem?
Then either post them here or send an email to support@oxygenxml.com.

Regards,
Radu

Re: XSPEC and XSLT issue

Posted: Tue Apr 21, 2015 1:27 pm
by tsm21
first_input

Code: Select all

<data>
<class>
<object ID="1">
<ID>1</ID>
<name>abc</name>
<weight>50</weight>
</object>
<object ID="2">
<ID>2</ID>
<name>def</name>
<weight>75</weight>
</object>
</class>
</data>
second_input

Code: Select all

<data>
<class>
<object ID="2">
<ID>2</ID>
<name>def</name>
<weight>75</weight>
</object>
<object ID="3">
<ID>3</ID>
<name>ghi</name>
<weight>100</weight>
</object>
</class>
</data>
compare_XSL file

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:strip-space elements="*"/>

<!-- PARAMETERS -->
<xsl:param name="p1" >second.xml</xsl:param> <!-- Provide full path of input-->


<xsl:variable name="s.root" select="/" />

<xsl:variable name="s.new" select="document($p1)" />

<!-- Template to detect the interfaces - Removed in input file -->

<xsl:template match="/">
<Data>

<class>
<xsl:apply-templates select="$s.root//class/object"
mode="first_compare" />
<xsl:apply-templates select="$s.new//class/object"
mode="second_compare" />
</class>
</Data>


</xsl:template>

<xsl:template match="//object" mode="first_compare">
<xsl:variable name="key1" select="ID" />

<xsl:variable name="context" select="$s.new//object[ID=$key1]"/>

<xsl:choose>
<xsl:when test="$context">
<!-- when true, it ignores -->
</xsl:when>

<xsl:otherwise>


<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>

</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="//object" mode="second_compare">
<xsl:variable name="key1" select="ID" />
<xsl:variable name="context" select="$s.root//object[ID=$key1]"/>

<xsl:choose>
<xsl:when test="$context">
<!-- when true, it ignores -->
</xsl:when>

<xsl:otherwise>


<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>

</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- copy root template -->
<xsl:template match="object" mode="copy_root">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- general copy -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
XSPEC_FILE

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="file:/D:/Sai/ALM_TASK779966/Oxygen/065_XSLT_ANT/compare.xsl">

<x:param name="p1" >second.xml</x:param> <!-- provide full path if required-->

<x:scenario label="when comparing two xml files">
<x:context href="first.xml"/> <!-- provide full path if required-->

<x:expect label="should display differences of two xml files">
<Data>
<class>
<object ID="1">
<ID>1</ID>
<name>abc</name>
<weight>50</weight>
</object>
<object ID="3">
<ID>3</ID>
<name>ghi</name>
<weight>100</weight>
</object>
</class>
</Data>
</x:expect>
</x:scenario>
</x:description>
The xspec file is unable to recognize the following line in xsl file.
i.e "/" is not been recognized by xspec file.

<xsl:variable name="s.root" select="/" />

could you please identify the issue?

Thanks for your help,
Sai

Re: XSPEC and XSLT issue

Posted: Wed Apr 22, 2015 5:01 pm
by adrian
Hello,

Thank you for the samples.
During initial testing we have not been able to reproduce the problem you are describing.
We will continue investigating and come back to you with the result.

BTW, what version and build of Oxygen are you currently using (Help > About)?
Also, are you using the standalone edition of Oxygen or the Eclipse plugin?

Regards,
Adrian

Re: XSPEC and XSLT issue

Posted: Thu Apr 23, 2015 8:11 am
by tsm21
Hello,

Oxygen XML Editor 16.1, build 2014112517

I am using standalone Oxygen XML editor.


Thank you
Regards
Sai

Re: XSPEC and XSLT issue

Posted: Fri Apr 24, 2015 9:04 am
by tsm21
Hello,

I have another issue regarding the usage of global parameters in XSPEC.

I have global parameters (say, p1,p2,p3) in XSL file where the values of the paramters change accordingly.

So I have written an XSPEC with global parameters in it , so that i could pass the values to the XSL file.

Now, i have to write different test scenarios and the values of global parameters need to change accordingly. But i am unable to pass different values at the same time.

for example:

Test scenario 1:
p1=input.xml
p2=A1
p3=A2

Test scenario 2:
p1=input.xml
p2=B1
p3=B2

is it possible to have different values for global parameters in XSPEC file at the same time?

could you please help me with is issue?


Thankyou
Sai

Re: XSPEC and XSLT issue

Posted: Fri Apr 24, 2015 10:33 am
by radu_pisoi
Hello,

The first reported problem is related to the different evaluation context used when computing the value of the global variable 's.root' from an XSLT or XSpec transformation.

From a regular XSLT transformation, the value of an XSLT global variable is computed by evaluating the XPath expression specified by the select attribute based on the initial context node, that usually is the root of the XML instance provided to the transformer.

Code: Select all


<xsl:variable name="s.root" select="/" />
In your case, the value of the s.root variable is the root element of the XML instance given to the transformer.

When running from the XSpec transformation, the XML document provided to the XSLT transformation is the XSpec document itself. So, the value of the s.root variable will be root of the XSpec document which is not what you are expecting I suppose.

You can check https://code.google.com/p/xspec/source/ ... /build.xml which is the build file used when running an XSpec test case.

To fix the problem, you can put an x:param element at the top level of the XSpec description document (as a child of the <x:description> element). This effectively overrides any global parameters or variables that you have declared in your stylesheet.

See the Global Parameters section: https://code.google.com/p/xspec/wiki/Wr ... Parameters

So, in your case you have to add an XSpec parameter as the child of XSpec root:

Code: Select all


<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="compare_XSL%20file.xsl">
<x:param name="p1">first_input.xml</x:param> <!-- provide full path if required-->
<x:param name="s.root" href="second_input.xml" />
...

Re: XSPEC and XSLT issue

Posted: Fri Apr 24, 2015 11:12 am
by radu_pisoi
Hello,

Related to the second problem, when you want to set specific values to the global parameters from different test scenarios.

According to the XSpec documentation, https://code.google.com/p/xspec/wiki/Wr ... Parameters, I understand that this is a limitation of the current XSLT-based implementation.
With the current XSLT-based implementation, it isn't possible to have different scenarios use different values for global parameters. Hopefully that will come with an XProc-based implementation. Testing is made easier if you declare local parameters on any templates or functions that use global parameters; these can default to the value of the global parameter, but be set explicitly when testing.
The XSpec specification also gives you an workaround, to declare local parameters in the templates that use global parameters and specify a different value from your test cases.

Re: XSPEC and XSLT issue

Posted: Fri Apr 24, 2015 1:53 pm
by tsm21
Hello,

Thank you for the solution.

We have one more doubt regarding the expected output given in <X: expect> in the above xspec file.

<x:expect label="should display differences of two xml files">

The above xspec file have small expected output file. But if we have huge output file to be given in the <x:expect>, the file size would increase and could be difficult to test.

Is there any way to provide the expected output file through a link or href?


Thank you
Regards
Sai

Re: XSPEC and XSLT issue

Posted: Fri Apr 24, 2015 4:10 pm
by radu_pisoi
Hello,

To use the content of an external file as expected result you can use the attribute: x:expect/@href.

Code: Select all


<x:expect label="should display differences of two xml files" href="expected.xml"/>
Also, you can specify the attribute x:expect/@select that allows you to point a specific xml fragment throught an XPath expression.

Re: XSPEC and XSLT issue

Posted: Mon Apr 27, 2015 12:59 pm
by tsm21
Hello,

Thanks for the solution.

Suppose in the input xml file, if we mention time stamp attribute like

<data timestamp="{current-dateTime() }">

Then time stamp keeps changing for each transformation but the time stamp information given in expected output will remain same.

So, the test case will never pass.

Is there a way (like ignoring the time stamp) while executing XSPEC file such that we get an exact match btw transformed output and expected output without changing the code in XSL file?

Thank you for the help.


Regards
Sai

Re: XSPEC and XSLT issue

Posted: Mon Apr 27, 2015 3:51 pm
by radu_pisoi
Hello,

As far as I know, the function current-datetime() is evaluated only once per transformation by an XSLT processor.

So, a solution can be to refactor your XSLT stylehseet to declare a global parameter that binds the value of the current-datetime() function and refer it instead of the function.

The second step is to supply a specific value for this parameter from your XSpec file.
This way, the stylesheet result will not depend on the value of the current-datetime() function when it is used from the XSpec file.

Re: XSPEC and XSLT issue

Posted: Tue May 05, 2015 8:03 am
by tsm21
Hello,

Thank you for the solution.

We have modified the XSL file and XSPEC file by adding the current-datetime() as a parameter.

xml_compare.xspec

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="file:/D:/Sai/ALM_TASK779966/Oxygen/065_XSLT_ANT/compare.xsl">

<x:param name="p1" >file:/D:/Sai/ALM_TASK779966/Oxygen/second.xml</x:param>
<x:param name="s.root" href="file:/D:/Sai/ALM_TASK779966/Oxygen/first.xml" />
<x:param name="dateTime">2015-04-04T11:13:35.475+05:30</x:param>

<x:scenario label="when comparing two xml files">
<x:context href="file:/D:/Sai/ALM_TASK779966/Oxygen/first.xml"/>

<x:expect label="should display differences of two xml files" href="compare_expectedOutput.xml"/>

</x:scenario>
</x:description>
compare_expectedOutput.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Data timestamp="2015-04-04T11:13:35.475+05:30" >
<class>
<object ID="1">
<ID>1</ID>
<name>abc</name>
<weight>50</weight>
</object>
<object ID="3">
<ID>3</ID>
<name>ghi</name>
<weight>100</weight>
</object>
</class>
</Data>
compare.xsl

Code: Select all

<xsl:variable name="s.root" select="/" />

<xsl:variable name="s.new" select="document($p1)" />

<xsl:variable name="dateTime" select="current-dateTime()" />

<!-- Template to detect the interfaces - Removed in input file -->

<xsl:template match="/">
<Data timestamp="{$dateTime}">............

Now when the XSPEC file is executed we get a test coverage report in html file.
There we see that the RESULT and EXPECTED RESULT are same but the test case is getting failed.

Could you please help me solve this issue?



Thank you
Regards
Sai

Re: XSPEC and XSLT issue

Posted: Tue May 05, 2015 8:10 am
by tsm21
Hello,

Also is it possible to transform a relaxNG(.rng) file(INPUT) into an XML file(OUTPUT) through XSL file?






Thank you
Regards
Sai

Re: XSPEC and XSLT issue

Posted: Tue May 05, 2015 11:40 am
by radu_pisoi
Also is it possible to transform a relaxNG(.rng) file(INPUT) into an XML file(OUTPUT) through XSL file?
I'm afraid I don't understand your use case. RELAX NG is a schema language for XML similar with XML Schema or DTD.

Do you want to generate one or more XML instances based on a RelaxNG schema? If not, could you give us more details about your use case?

Re: XSPEC and XSLT issue

Posted: Tue May 05, 2015 11:55 am
by tsm21
Hello,

we want to generate an XML file as output by xsl transformation with input as relax NG file.



Thanks
Sai

Re: XSPEC and XSLT issue

Posted: Tue May 05, 2015 12:28 pm
by radu_pisoi
tsm21 wrote: Now when the XSPEC file is executed we get a test coverage report in html file.
There we see that the RESULT and EXPECTED RESULT are same but the test case is getting failed.

Could you please help me solve this issue?
It works after I modify a bit the expected result:

Code: Select all


<x:expect label="should display differences of two xml files" 
href="compare_expectedOutput.xml"
select="/*"/>
I suppose that this happens because the XSPec engine compares two different types of nodes: an element(which is the result of the transformation) and a document-node which is the the result of the x:expect instruction.

In the future, for more precise/suitable answers, I think it would be better to address such kind of questions to the XSpec team. The main page for the XSpec project is https://code.google.com/p/xspec/ where you can find a dedicated section for issues.

Re: XSPEC and XSLT issue

Posted: Thu May 07, 2015 1:49 pm
by tsm21
Hello,

Thank you for your help and support.

We have a doubt whether a relaxNG file could be transformed into an XML file using XSLT?


When we tried to do the transformation a warning/error is displayed on (Oxygen XML editor) console saying that

"Warning! The source document is in namespace http://relaxng.org/ns/structure/1.0, but all the template rules match elements in no namespace (Use --suppressXsltNamespaceCheck:on to avoid this warning)"

demo.rng

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<start>
<ref name="data"/>
</start>....... </grammar>
Is it even possible to transform a relaxNG file into XML file?

INPUT(.rng file)-----> XSLT(.xsl file)------>OUPUT(.xml file)

please help us solve this issue.




Thank you
Sai

Re: XSPEC and XSLT issue

Posted: Thu May 07, 2015 6:13 pm
by adrian
Hi,

If it's XML well-formed then it can be parsed and transformed.

Note that it's not the RNG that's the problem, it's your XSLT stylesheet that is unaware of the namespace http://relaxng.org/ns/structure/1.0. You need to adjust your stylesheet to account for the namespace, or simply ignore namespaces.

Regards,
Adrian

Re: XSPEC and XSLT issue

Posted: Fri May 22, 2015 7:59 am
by tsm21
Hello,

Is it possible to transform a text file into a flat XML file using XSLT?

sample.txt

Code: Select all

As is text
!ITEM_NAME
Item value
!ANOTHER_ITEM
Its value
As is text2
!TEST_BANG
Here's a value with !bangs!!!
!TEST2_BANG
!!!Here's a value with !more~ !bangs!!!
As is text3
Thanks in advance for your help.



Thank you
Sai

Re: XSPEC and XSLT issue

Posted: Fri May 22, 2015 4:58 pm
by radu_pisoi
Sure. You can read a text document with unparsed-text() function. To process it, one solution is to use the xsl:analyze-string instruction.

Re: XSPEC and XSLT issue

Posted: Mon May 25, 2015 7:38 am
by tsm21
Hello,

Thank you for the solution...

we have created a sample xslt file and text file.

sample_txtfile.txt

Code: Select all

StartThing
Size Big
Colour Blue
coords 42, 42
foo bar
EndThing
StartThing
Size Small
Colour Red
coords 29, 51
machin bidule
EndThing

sample_xslt.xsl

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:param name="text-encoding" as="xs:string" select="'iso-8859-1'"/>
<xsl:param name="text-uri" as="xs:string" select="'sample_txtfile.txt'"/>

<xsl:template name="text2xml">
<data>
<xsl:variable name="text" select="unparsed-text($text-uri, $text-encoding)"/>
<xsl:analyze-string select="$text" regex="(Size|Colour|coords) (.+)">
<xsl:matching-substring>

<xsl:element name="{(regex-group(1))}">
<xsl:value-of select="(regex-group(2))"/>
</xsl:element>

</xsl:matching-substring>
</xsl:analyze-string>
</data>
</xsl:template>

<xsl:template match="/">
<xsl:call-template name="text2xml"/>
</xsl:template>
</xsl:stylesheet>

The issue we face while executing the xslt file is displayed in the console as follows:

D:\Sai\abc\xyz\sample_txtfile.txt:1:1: Fatal Error! Error reported by XML parser Cause: org.xml.sax.SAXParseException; systemId: file:/D:/Sai/abc/xyz/sample_txtfile.txt; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.



could you please help us to identify the problem?




Thank you
Sai

Re: XSPEC and XSLT issue

Posted: Mon May 25, 2015 2:28 pm
by radu_pisoi
This can happen when the input XML file is not well-formed. So, I suppose that you have selected the text file (sample_txtfile.txt) as input XML file when you have edited the XSLT scenario (see the XML URL field from the XSLT tab when you edit the scenario).

However, for your use-case it is not required to set an input XML file. You can set the initial template to text2xml. To set the initial template you have to select Saxon 9.6 as the XSLT processor and edit its advanced options.

Otherwise, you have to select an wellformed XML as the input XML of the transformation scenario.

Re: XSPEC and XSLT issue

Posted: Thu May 28, 2015 12:32 pm
by tsm21
Hello,

we are unable to read text document directly with unparsed-text() function and xsl:analyze-string instruction.

And we are able to read and process the text file with xsl only if we add an element at the beginning and end of the text file.

for example <root> element is added to the below text file.

Code: Select all


<root>
StartThing
Size Big
Colour Blue
coords 42, 42
foo bar
EndThing
</root>
So is there any way to read the text file without adding element at the start and end of the input text file?



Thank you
Sai

Re: XSPEC and XSLT issue

Posted: Thu May 28, 2015 3:03 pm
by adrian
Hi,

Note that the problem with this error:

Code: Select all

D:\Sai\abc\xyz\sample_txtfile.txt:1:1: Fatal Error! Error reported by XML parser Cause: org.xml.sax.SAXParseException; systemId: file:/D:/Sai/abc/xyz/sample_txtfile.txt; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
is not with the unparsed-text() function. The problem is that you are using the same .txt file as the source XML file (in the 'XML URL' field) from the XSLT transformation scenario. You need to use a well-formed XML file (any other) in that field (or avoid that completely and use an initial template, like Radu proposed). A quick workaround is to create a separate dummy .xml file with an XML root and set that as the XML source (int the 'XML URL' field).

e.g. dummy.xml

Code: Select all

<root/>
Regards,
Adrian

Re: XSPEC and XSLT issue

Posted: Thu Jun 04, 2015 8:26 am
by tsm21
radu_pisoi wrote:
This can happen when the input XML file is not well-formed. So, I suppose that you have selected the text file (sample_txtfile.txt) as input XML file when you have edited the XSLT scenario (see the XML URL field from the XSLT tab when you edit the scenario).

However, for your use-case it is not required to set an input XML file. You can set the initial template to text2xml. To set the initial template you have to select Saxon 9.6 as the XSLT processor and edit its advanced options.

Otherwise, you have to select an wellformed XML as the input XML of the transformation scenario.


Thank you for the solution. but could you please briefly explain on how to set an initial template as we could not find any options to set it.




Thank you
Sai

Re: XSPEC and XSLT issue

Posted: Thu Jun 04, 2015 4:54 pm
by Costin
Hello,

In order to set an initial template, you should edit your transformation scenario, in the "Configure Transformation Scenario(s)" dialog.
Once in the scenario editing dialog, in the XSLT tab on the "Transformer" field (where you have Saxon 9.6.0.5 selected), you should click the "Advanced options" small widget (it looks like a small yellow gearwheel).

In the following Saxon 9.6.0.5 configuration window, you should set the template's name (text2xml) in the Template("-it") field under the "Initial mode and template" section.

Regards,
Costin

Re: XSPEC and XSLT issue

Posted: Fri Jun 05, 2015 9:12 am
by tsm21
Hello,

Actually we have downloaded the latest Saxon 9.6.0.5 jar file and copied it in the lib folder of oxygen XML editor home directory (../Oxygen XML Editor 16/lib).

We have restarted the editor to make sure the changes are saved.

We are still able to see the previous Saxon version but not the latest file in

"Configure Transformation Scenario(s)-->Edit-->Transformer field"

Is there a way to reflect the latest Saxon version in the editor?





Thank you
Sai

Re: XSPEC and XSLT issue

Posted: Fri Jun 05, 2015 12:24 pm
by ionela
Hi,

Please note that because of the tight integration (validation, debugging, etc), you cannot upgrade the version of Saxon 9 that comes bundled with oXygen. Saxon 9.6 is bundled with v17.0 of oXygen.

Is there any specific reason why you need to use Saxon 9.6? If you want to use this specific version of Saxon you need to install oXygen v17.0.

Now, as you have altered the Saxon jar file from the lib folder of oXygen installation directory, you need to replace this file with the original one (if you have created a backup) or reinstall the application. oXygen does not work as expected and we do not provide support for using the application with a different Saxon version than the one it comes integrated with.

Regards,
Ionela

Re: XSPEC and XSLT issue

Posted: Tue Jun 30, 2015 9:12 pm
by ajbufort
Can you please confirm what exact version of Saxon PE is included with oXygen 17.0? Is it 9.6.0.6?

Thanks.