How can I retrieve the current working directory with XSLT version 1.0?
I have already looked at these posts here:
XSL, get current working directory
How to get current document uri in XSLT?
But it requires version 2.0 and I am not sure if I have that as when I tried switching to 2.0 I get an error.
Here are the XSL snippets I tried:
<xsl:variable name="myURI" select="resolve-uri('my.xsl')"/>
or
<xsl:variable name="myURI" select="document-uri(document(''))" />
and in both cases I get errors:
Error! Error checking type of the expression 'funcall(resolve-uri, [literal-expr(junit-frames.xsl)])'.
Fatal Error! Could not compile stylesheet
Error! Error checking type of the expression 'funcall(document-uri, [funcall(document, [literal-expr()])])'.
Fatal Error! Could not compile stylesheet
Then I also saw this post here: xslt get the file current folder path
But as I am an XSLT newbie I don't understand the answer or how to implement it. Can anybody provide an example snippet? Thanks!
You say in a comment that you're using the processor "which comes with Ant 1.8.2". In that case the simplest answer may be to pass in the current directory as a parameter
<xslt style="stylesheet.xsl" in="in.xml" out="out.xml">
<param name="basedir" expression="${basedir}" />
</xslt>
and in your stylesheet add a top-level
<xsl:param name="basedir" />
Now you have access to the current directory path as $basedir.
If you need the path as a URI rather than a native file path you can use makeurl:
<makeurl file="${basedir}" property="basedir.url" />
<xslt style="stylesheet.xsl" in="in.xml" out="out.xml">
<param name="basedir" expression="${basedir.url}" />
</xslt>
Related
I would like to dynamically generate the Schematron see attribute based on the the user home's directory. I could not get this working. Do you have an idea if this is possible? It needs to work in Oxygen XML. I am not sure if this is technically not possible in Schematron, or if this is a bug in Oxygen XML.
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
<sch:pattern>
<sch:rule context="/">
<sch:let name="x" value="if (contains(base-uri(), 'myname'))
then 'http://www.a.com'
else 'http://www.b.com'"/>
<sch:report test="'a' = 'a'">
Hello world: "<sch:value-of select="$x"/>"
</sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>
My goal is to generate a user-specific link to a locally deployed style guide, but, as you can see in the screenshot, the variable x is not resolved.
Maybe you can try to read the “user.home” system property: https://www.saxonica.com/html/documentation12/functions/fn/system-property.html
Using Schxslt it seems the syntax of an XSLT attribute value template in the form of e.g. see="{$x}" in Schematron then generates an SVRL report having the URI in the form of e.g.
<svrl:successful-report location="/" see="http://www.b.com" test="'a' = 'a'">
<svrl:text>
Hello world
</svrl:text>
</svrl:successful-report>
I don't know whether oXygen has any integration for Schxslt as a Schematron validator and for rendering the validation result in the form of SVRL.
To build on the answer by #radu-coravu, you might be able to get the 'user.home' value by using a function in an external XSLT file:
Use xsl:include in your Schematron file to include the XSLT. See, e.g., https://github.com/AntennaHouse/focheck/blob/43bd5d491d8b985395c94c3c53083770d8c461b6/schematron/fo-property.sch#L23
Write a function in the external XSLT that returns the "user.home" system property value
In your rule in your Schematron, use let to get the return value of the function as a variable value. See, e.g., https://github.com/AntennaHouse/focheck/blob/43bd5d491d8b985395c94c3c53083770d8c461b6/schematron/fo-property.sch#L31
Use the Schematron variable in your assert and report just like any other variable
I am planning to used XSL version 3.0 for my WSO2 EI application. Because, I need to map JSON to JSON and JSON to XML in my application. Currently I have try with version 2.0. Please refer following code for current implementation.
I need to know how change this version and which jar required in WSO2EI for xsl version 3.0.
<?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" />
<xsl:param name="STATIC_BODY_PARAM"></xsl:param>
<xsl:template match="/availabilityRequest">
<availabilityRequest>
<control>
<userName>
<xsl:value-of select="control/userName" />
</userName>
<passWord>
<xsl:value-of select="control/passWord" />
</passWord>
</control>
....................
</availabilityRequest>
</xsl:template>
</xsl:stylesheet>
When I used version as 3.0, I got following error message. I have added your further reference.
ERROR - XSLTMediator Error creating XSLT transformer using : Value {name ='null', expression =fn:concat('gov:repository/transformation/',$ctx:uri.var.travel_type,'_',$ctx:uri.var.activity,'_',$ctx:uri.var.supplier_id,'_in.xslt')}
net.sf.saxon.trans.LicenseException: Requested feature (XSLT 3.0) requires Saxon-PE
at net.sf.saxon.Configuration.checkLicensedFeature(Configuration.java:584)
at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(PreparedStylesheet.java:331)
at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:207)
at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:132)
at org.apache.synapse.mediators.transform.XSLTMediator.createTemplate(XSLTMediator.java:467)
I don't know anything specifically about WSO2EI, but it appears (from your link) that it is currently running with some older version of Saxon-HE.
Simply substituting the Saxon 9.9 JAR file for the one that is distributed with the product may work, or it may not. It's very likely to work, but it's possible that the stylesheets, or the calling application, depend on something in Saxon that has changed.
If you've tried something, there's no point telling us it doesn't work. You need to tell us exactly how it failed.
You should try running a stylesheet that outputs the value of system-property('xsl:product-version') so you have positive confirmation of which Saxon version is being picked up.
You don't need to make any changes to your stylesheets to use XSLT 3.0 features, but it's a good idea to change the version attribute to version="3.0" for documentation reasons.
I have fixed above problem using following information.
I got the 30 trail license key with registering http://www.saxonica.com/download/download.xml (saxon-license.lic) and it put into /wso2ei-6.4.0/ folder
Remove this jar (saxon.he_9.4.0.wso2v1.jar) on following location. (/wso2ei-6.4.0/wso2/components/plugins)
Also put this jar (saxon9ee.jar) http://www.saxonica.com/download/SaxonEE9-4-0-6J.zip into /wso2ei-6.4.0/lib location
Restart the wso2ei-6.4.0 server
Now xsl:stylesheet version="3.0" working without any issue.
I have got those details from following link. Many thanks for that.
http://nandikajayawardana.blogspot.com/2012/12/how-to-replace-saxonhe940wso2v1jar-in.html
I'm trying to get content from another XML file in the same directory as my XML file. However, I don't know how to get the uri of the source XML. The XSLT keeps relating to its own directory.
How can I get the URI of the source XML?
I would recommend document-uri() rather than base-uri(). It will usually be the same, but base-uri() is affected by the xml:base attribute and by use of XML external entities, while document-uri() is not.
You can use the base-uri() function:
<!-- your external XML -->
<xsl:variable name="doc" select="document('http://www.xyz.com./path/your-doc.xml')"/>
<!-- the base URI of your external XML -->
<xsl:variable name="doc-base-uri" select="base-uri($doc)"/>
I found an answer that worked for me.
I got it using base-uri(.).
After a lot of spent time trying to get my article to compile in Ant with Docbook, I can't seem to make FO compilation work. I'm using Xalan 2.7.0, and everything else (both single-page and chunked HTML) compiles perfectly. It's only when I try to compile to FO that I get this error:
Fatal Error! org.apache.xml.utils.WrappedRuntimeException: Could not find variable with the name of fop.extensions Cause: org.apache.xml.utils.WrappedRuntimeException: Could not find variable with the name of fop.extensions
This is pretty strange and I can't seem to resolve it. I even added a <param> value defining the variable it "can't find:"
<xslt style="docbook-xsl/fo/fo.xsl" in="documents/book.xml"
out="output.fo">
<classpath>
<fileset dir="lib" includes="**/*"/>
</classpath>
<param name="fop.extensions" expression="1"/>
</xslt>
Is there anything I can do to resolve this issue? It's really weird if you ask me. (Again, using the same code as above, all of my other Docbook compilation works just fine)
Instead of using fo/fo.xsl, try fo/docbook.xsl. That is the main stylesheet for XSL-FO output.
I have 3 XSL files which have paths in them to something like C:\templates\Test\file.pdf
This path isn't always going to be the same and rather than having it hard coded in the XSL, I'd like it so that the path C:\templates\test\ is replaced with a tag [BASEPATH] and when I read in the xsl file into the XSLTransform object (yes I know it's been deprecated, I may move over to the XSLCompiledTransform at the same time), I'd like the tag [BASEPATH] to be replaced with the absolute file path of the web folder (or Server.MapPath("~") seeing as it is in .net)
I thought I may be able to make an XSLLoader aspx page which takes the name of the XSL file through the querystring and then returns the XSL file via xml content-type. When I try this, I get a 503 error though so I'm not sure if you can pass urls like this into the XSLTransform.Load method.
Any ideas what to do?
Have you looked at XSL parameters?
<xsl:param name="basepath" select="'C:\Users\Graeme\'" />
<xsl:value-of select="document(concat($basepath, 'test.pdf'))" />
Then, most decent XSLT engines have a way to set a root level parameter from outside.