FAQ Database Discussion Community


Use XSLT to mark up text matching regex?

xml,xslt,unicode,xslt-2.0,saxon
I am trying to use XSLT 2.0 (Saxon-PE 9.6) on an HTML document to create tags that surround all contiguous runs of characters from a specified non-Latin Unicode block (spaces allowed). I need to apply this process to every text() node in the document. I have made some progress with...

XSL XML transformation, changing namespace value

java,xslt,namespaces,xslt-1.0,saxon
i'm trying to remove some elements from xml using xsl and also to change a namespace value declared in sub1 element. The problem is, when i change the namespace value, the old namespace declaration is inserted into a child element (sub2 in the example), how can i change the code...

SAXON Error- How to ignore/skip it?

javascript,xslt,batch-processing,saxon
Using Saxon HE (net version) wget and batch, I'm trying to transform a page I've downloaded via wget. Whenever calling the command on the page, I get the following error: SXXP0003: Error reported by XML parser: The entity name must immediately follow the '&' in the entity reference. It is...

XQuery document node test with an element node test in BaseX 8.2 throws in the presence of comments before the root element. Why?

xml,xslt,xquery,saxon,basex
In BaseX 8.2, I'm trying to assign to an XQuery variable, a document node whose root element has a specific name. The source XML looks like this: <?xml version="1.0" encoding="utf-8"?> <!--A comment--> <myRootElement/> To get the document node, I type-check it using a DocumentTest: declare variable $docnode as document-node(element(myRootElement)) :=...

Modifying XPath 2.0 result trees using Saxon

saxon,xpath-2.0
I would like to add/remove/update elements/attributes/values to the "subTree" be able to save the updated "targetDoc" back to the "target" file location. determine which tree model would be best for this xpath + tree modification procedure. I thought I should somehow be able to get a MutableNodeInfo object, but I...

Saxon HE and XQuery: Unexpected token “

xquery,eof,saxon
I copy paste this example from http://www.w3schools.com/xquery/xquery_functions.asp (though I added the namespace declaration): declare namespace local="local"; declare function local:minPrice($p as xs:decimal?,$d as xs:decimal?) as xs:decimal? { let $disc := ($p * $d) div 100 return ($p - $disc) }; But when I try to run it, the SAXON output is:...

generating a document with list of files in a directory using xslt 2.0

xml,xslt,saxon
I have a bunch of folder with party xml files and partly binary image files. I am generating a list of those files, using the following: <xsl:variable name="string" select="iri-to-uri(concat(@name, '/?select=*.(xml|gxf)'))"/> <xsl:variable name="input" select="collection($string)"/> <xsl:for-each select="$input"> <file> <xsl:value-of select="tokenize(document-uri(.), '/')[last()]"/> </file> </xsl:for-each> Works well, except of course for the binary files....

Saxon XSLT: Serializer producing weird indents

c#,xslt,saxon
I'm using Saxon HE 9.5.1.8 to transform an XML to another XML file. My problem is that the XML content written by the Serializer() class of Saxon prints out several additional indents that I don't want to have in there. I'm assuming that this is "wrong" because I got the...

SAXON - Calling external java functions in Xquery

java,xml,xquery,saxon
I have a requirement to invoke java function in Xquery using Saxon processor.I came to know that saxon has various editions like home, professional, enterprise editions. I am looking for a open source edition which can help me to invoke external java functions in xquery. Can somebody please help me...

how to refer dynamically an xml file in Xquery in saxon

java,xml,xquery,saxon,xqj
I am using XQuery processor Saxon,Now we write our Xquery in a ".xqy" file where we refer the xml file on which we will perform Xquery.please see the example below- for $x in doc("books.xml")/books/book where $x/price>30 return $x/title Now I want to use dynamically generated xml not stored in some...

Java Saxon Parsing

java,saxon
I'm using Saxon parser to split the big file into smaller ones. Below is my sample code, TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory .newTransformer(new StreamSource(new File(xsltPath))); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); transformer.transform(new StreamSource(new File(sourcePath)), new StreamResult(new File(resultDir))); Where sourcePath = C:/path/Temp/AppModule.xml xsltPath =...

Generate a XML from some defined XPATH

xml,xslt,xpath,saxon,xalan
I am trying to generate a XML from another XML based on some defined XPATH. XPATH: country/name, country/org_id, country/lang, country/currency, generate_date, schedule/category/id, schedule/category/name, schedule/category/classes/class/id, schedule/category/classes/class/duration, schedule/category/classes/class/price, schedule/category/classes/class/instruction_language Xpath is excluding the name of root node and it is a list. XML: <?xml version="1.0" encoding="utf-8" ?> <ou_schedule> <country> <name>Country...

Get text between two self-closing elements and number of following/preceding element

xml,xslt,xslt-2.0,saxon
<text> <pb n="I"/> <p> <lb/>Lorem ipsum <lb/>Lorem ipsum <lb/>Lorem ipsum <pb n="II"/> <lb/>Lorem gipsum <lb/>Lorem gipsum </p> <p> <lb/>Lorem gipsum <lb/>Lorem gipsum <pb n="III"/> <lb/>Lorem hipsum <lb/>Lorem hipsum <lb/>Lorem hipsum <lb/>Lorem hipsum </p> <pb n="IV"/> <p> <lb/>Lorem dipsum </p> </text> From such a document, I am trying to get all...

XSLT template not applying to newly-created elements

xml,xslt,xslt-2.0,saxon
I am using XSLT 2.0. Inside a xsl:template (template-1), I use xsl:analyze-string to create new span elements with an xml:lang attribute. I have a second template (template-2) that adds a class attribute to elements that contain a xml:lang attribute. In my stylesheet, the newly-created span elements created by the first...

how to call all the files inside a folder using batchfile

windows,batch-file,cmd,batch-processing,saxon
java -Xss2048k -jar -DentityExpansionLimit=800000 "C:\testXsl\saxon9.jar" "C:\testXsl\In\" "C:\testXsl\XslFile\test.xsl" >"C:\testXsl\Out\out.xml" 2>"C:\testXsl\Logs\xsllog.xml" how can i select all .xml files inside the C:\testXsl\In\ folder thanks??...

XML Schema 1.1 assertions: How to catch a dynamic type error?

xml,saxon,xsd-validation,assertion,xsd-1.1
I'm currently struggling with assertions in XML Schema 1.1. The XML Schema 1.1 recommendation states that an assertion is violated if an error occurs during its execution. This behavior seems reasonable, but might cause some confusion when trying to understand evaluation results. Let me explain: The following example XSD explains...

Using xsl:accumulator with xsl:try/xsl:catch

xml,xslt,saxon,xslt-3.0
I have very large input document (thousands of Records) that has a structure something like this (Data represents many child elements): <Input> <Record id="1"> <Data/> </Record> <Record id="2"> <Data/> </Record> <Record id="3"> <Data/> </Record> <Record id="4"> <Data/> </Record> <Record id="5"> <Data/> </Record> <Record id="6"> <!-- This is bad data -->...

How to capture xsl:message output using Saxon XSLT transformer in PowerShell

powershell,xslt,saxon
I cannot find a way to capture the <xsl:message/> output of the .NET Saxon XSLT transformer when running via PowerShell. I've tried various PowerShell methods of capturing output and various ways to tell Saxon to output the data without success. I need to use the Saxon XSLT library because our...

Why is this choose-when-test always true?

xslt,saxon
In an XSLT file I have defined a function <xsl:function name="my:isValidDate"> <xsl:param name="orgDate" /> <xsl:value-of select="boolean(string-length($orgDate)=10)" /> </xsl:function> to test whether a date string has a valid length. When I use this function <xsl:choose> <xsl:when test="my:isValidDate(ValidFrom)"> <xsl:call-template name="formatDate"><xsl:with-param name="orgDate" select="ValidFrom"></xsl:with-param></xsl:call-template> </xsl:when> ......

How to improve eXSLT performance problems when using functions

python,xml,xslt,saxon
TL;DR: It seems than running eXSLT is waay slower than its counterpart in XSLT2. (7 minutes vs 18 hours) Below I explain my problem, writing down both implementations of the same transform, in eXSLT and XSLT2. Of course, engines are different, as for XSLT2 i use SaxonHE, and for eXSLT...

XSLT collection() function regex not recognizing '?'

xslt,saxon
I'm trying to grab 3.XML through 6.XML from the list below: 3.XML 4.XML 4_1.XML 5.XML 5_1.XML 6.XML 31.XML collection('file:///.../?select=[3-6](_[0-9]+)?.XML only grabs 4_1.XML and 5_1.XML and therefore doesn't recognize the '?'. Any suggestions on how to fix this? I'm using Saxon-PE 9.5.1.3. ...

Better way to store XdmValue in the database as XmlType using saxon.

java,oracle,saxon,xmltype
I am executing XQuery using Saxon 9API. The result of XQuery is returned as net.sf.saxon.s9api.XdmValue.I am constructing DOM document object from this XdmValue. I am pasting the code below. Processor saxon = new Processor(false); saxon.registerExtensionFunction(new MyExtension()); XQueryCompiler compiler = saxon.newXQueryCompiler(); XQueryExecutable exec = compiler.compile(new File("input/studentXQuery.xq")); XQueryEvaluator query = exec.load(); String...