Menu
  • HOME
  • TAGS

How to avoid ambiguous match for two different elements

xml,xslt,xslt-2.0

In general, if you get that warning (from Saxon?), it tells you exactly which two templates where matched and it takes the last one when transforming the sample. If that gives you the correct result and you don't want that warning, you can set an explicit priority="5" on the xsl:template...

copy the entire block under another node - xslt transformation

xml,xslt,xslt-2.0

You can move all result blocks in an added results block like that: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="result"> <results> <xsl:copy>...

Add Space Before a tag if it is Present in XSLT

html,css,xml,xslt,xslt-2.0

Try this to solve your issue : <xsl:template match="LEXVAR"> <span class="exp"> <xsl:if test="./preceding-sibling::*"> <xsl:text> </xsl:text> </xsl:if> <xsl:text></xsl:text> <xsl:apply-templates/> </span> ...

Match attribute on XSLT instead of matching the whole element

xml,xslt,xpath,xslt-2.0

You can indeed match attributes in your templates as your first template does. Something else must be wrong... Take a look at the identity transform: <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> It works fine matching alternatives as you're doing, and one of the alternatives is...

One single XSLT template to transform one XML into another which follows a slightly different XSD?

xml,xslt,xslt-2.0

If the XSDs governing the input and output XML documents are substantially similar, common practice is to use an identity transformation that will, by default, copy nodes exactly from input to output. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> For those nodes that should not be...

Remove repeated string in xslt

xml,xslt,xslt-1.0,xslt-2.0

Here is an XSLT 1.0 stylesheet adapted to your latest sample where the elements to be grouped are a nesting level further down the tree: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/> <xsl:key name="group" match="/*/*/*/property" use="@name"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy>...

How to remove xml tags only using xslt

xml,xslt,xslt-1.0,xslt-2.0

You can use this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="p"> <xsl:copy> <xsl:value-of select="normalize-space(.)"/> </xsl:copy> </xsl:template> </xsl:stylesheet> ...

Day difference between two dates in XSLT version 2.

xslt,xslt-2.0

You can subtract one xs:date from another one and then you get an xs:dayTimeDuration of which you can extract components e.g. xs:date('2015-06-11') - xs:date('2015-06-01') gives an xs:dayTimeDuration P10D and you can then call http://www.w3.org/TR/xquery-operators/#func-days-from-duration e.g. days-from-duration(xs:date('2015-06-11') - xs:date('2015-06-01')) which gives 10.

Is it possible for a template to use itself as the select attribute in a for-each-group?

xml,xslt,xpath,xslt-2.0

No, you need to replace an <xsl:apply-templates/> or <xsl:apply-templates select="orderedList"/> that processes the orderedList elements with your grouping code, e.g. <xsl:for-each-group select="current-group()" group-by="@level">...</xsl:for-each-group>. In the template with match="orderedList" you would always have only a single context node, not a group of nodes, so there would be nothing to group in...

Sequence number for static and dynamic rows in XSLT 2.0

xml,xslt-2.0

Would this XSLT do: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:strip-space elements="*"/> <xsl:template match="/*"> <xsl:apply-templates select=".//line"/> </xsl:template> <xsl:template match="line"> <xsl:variable name="pos" select="position() + (3 * count(preceding::data))"/> <xsl:value-of select="concat(format-number($pos, '00000 '), ., '&#xa;')"/> </xsl:template> <xsl:template...

Using XSLT for desired output

xml,xslt,xslt-2.0

Try it this way instead: <xsl:template match="/"> <People> <xsl:for-each select="Name/Person"> <Resident> <Number><xsl:number/></Number> </Resident> <Vehicle> <xsl:for-each select="Car"> <CarNumber><xsl:number level="any"/></CarNumber> </xsl:for-each> </Vehicle> </xsl:for-each> </People> </xsl:template> ...

Axis step child::element('':PRODUCT_LIST) cannot be used here: the context item is an atomic value

xslt,xslt-2.0

The error message says it all - when you are inside a for-each over 1 to count($PRODUCT_TYPE) the context item (.) is a number rather than a node, so you can't use a relative XPath in the value-of. You need to save the context item from outside the for-each in...

How to get repeated element from For-Each in XSLT 2.0

xml,xslt,xslt-1.0,xslt-2.0

Try it this way? <xsl:template match="/Data"> <Imdb> <xsl:for-each select="Movie"> <Film> <xsl:copy-of select="writer"/> </Film> </xsl:for-each> </Imdb> </xsl:template> I don't know what you mean by: I need to achieve the above mentioned task only with for each loop or for each group by loop. Surely you want to achieve the above task...

Precision, Rounding, and data types in XSLT2.0

xslt,decimal,rounding,xslt-2.0,data-type-conversion

Assuming there is no schema involved, the typed value of the element InvoiceAmount is xs:untypedAtomic - which essentially means a string, but one that adapts itself to the context in which it is used. If you do an explicit conversion to xs:decimal, the untypedAtomic value "-62.84" will convert exactly. If...

Changing the value of an attribute depending of the value of a second attribute of the same element

xml,xslt,xpath,xslt-2.0

Try these 3 templates (1st one is an identity template; second will "eat up" all @type; and third one will generate both attributes again, based on the @type): <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="//language/@type"/> <xsl:template match="//language/@lang"> <xsl:attribute name="lang"> <xsl:value-of select="."/> </xsl:attribute> <xsl:attribute name="type"> <xsl:choose>...

Reproduce XML with attributes using XSLT 2.0 & Grouping one element

xslt-2.0,xslt-grouping

I would push the elements to the identity transformation, see http://xsltransform.net/bdxtqy which does <?xml version="1.0" encoding="UTF-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:ws="http://example.com/"> <xsl:output method="xml" indent="yes" /> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="ws:Review"> <xsl:copy> <xsl:for-each-group...

How to generate random UUID using xslt

xml,xslt,xslt-2.0

The reason you are getting an error is that you are using an XSLT 2.0 processor (Saxon 9) which does not support the EXSLT math:random()) function. Unfortunately, there is no native random() function in XSLT 2.0 either, but with Saxon you can call a Java method - for example: <xsl:stylesheet...

XSL: How can I sort a three digit, hyphen separated value?

xml,sorting,xpath,xslt-2.0

You have the right idea, but you need to take it one step further: <xsl:sort select="substring-before(@id, '-')" data-type="number"/> <xsl:sort select="substring-before(substring-after(@id, '-'), '-')" data-type="number"/> <xsl:sort select="substring-after(substring-after(@id, '-'), '-')" data-type="number"/> With those three xsl:sorts together, it should sort the way you want....

Apply-templates with in Analyze string

regex,xslt-2.0

If you want to use apply-templates inside the analyze-string then you need to store the context node outside of analyze-string in a variable <xsl:variable name="context-node" select="."/>, then you can use <xsl:apply-templates select="$context-node/node()"/> for instance to process the child nodes. Whether you need that approach I am not sure, I wonder...

Copy all the sub elements of a root element except a given element

xml,xslt,xslt-2.0

XSLT 1.0 I am not sure if I understood you. But if the xml you want to get is the one in the end of your post, you can use: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="utf-8" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="node()"> <xsl:copy> <xsl:apply-templates select="node()" /> </xsl:copy> </xsl:template>...

is there a way to check if there is text between the nodes

xml,xslt,xslt-2.0

There is no need to use matches(). If the rule is whether the content-style element is the first child node of para, match for para[node()[position() = 1 and self::content-style]] Assuming the following input document, where both cases are present: XML Input <root> <para><content-style font-style="bold">1/3</content-style>YES</para> <para>NO <content-style font-style="bold">1/3</content-style></para> </root> XSLT Stylesheet...

Removing empty nodes with empty/no attributes using XSLT

java,xml,xslt,xslt-2.0

You should not make <xsl:apply-templates/> conditional - otherwise the stylesheet will stop at the first node that does not satisfy the condition, and it will never get to its children. BTW, if understand your conditions correctly, you could simplify this to: <xsl:template match="*[string() or @*[string()]]"> <xsl:copy> <xsl:copy-of select = "@*[string()]"/>...

unable to add element in xml using xslt

xml,xslt,xslt-1.0,xslt-2.0,xslt-grouping

Please try this solution. I have check it with XmlSpy. May be your online tool is not working fine. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="ABC_Login" exclude-result-prefixes="ns1" version="1.0"> <xsl:template match="/ns1:users"> <users> <email> <xsl:value-of select="ns1:email" /> </email> </users> </xsl:template> </xsl:stylesheet> ...

Split XML into multiple files using xslt on string length

xml,xslt,xslt-2.0

I only need the 2 files. legacy.xml (bookIds not 10 in length) & current.xml (bookIds with length of 10). Then I would suggest you do it this way: XSLT 2.0 <xsl:stylesheet version="2.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="/books"> <books> <xsl:copy-of select="book[string-length(bookId)=10]" /> </books> <xsl:result-document href="file:/C:/devFiles/legacy.xml"> <books> <xsl:copy-of...

XSLT multiple output: copy selected nodes and the rest too

xml,xslt,xslt-2.0

Couldn't it be simply: XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="xml" encoding="UTF-8" indent="yes" /> <xsl:strip-space elements="*" /> <xsl:template match="/car"> <xsl:for-each select="extras/extra"> <xsl:result-document href="extra{position()}.xml"> <car xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <extras> <xsl:copy-of select="*"/> </extras> <xsl:copy-of select="../../(* except...

equals not matching though declared

xslt,xslt-2.0

If you want to compare a string to a sequence of other strings then you need e.g. 'S' = ('A', 'B', 'D', 'S') so I think instead of xsl:when test="$ChpnMatch = 'B|D|E|L|R|F|H|K|Q|S'" you want xsl:when test="$ChpnMatch = ('B', 'D', 'E', 'L', 'R', 'F', 'H', 'K', 'Q', 'S')". That checks whether...

limiting variable with names to 127 chars, keeping whole names

xslt-2.0

Not efficient but <xsl:template match="Artists"> <Limit_Artists> <xsl:value-of select="Name[string-length(string-join((preceding-sibling::Name, .), '')) le 127]" separator="; "/> </Limit_Artists> </xsl:template> should do. A complete example is <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:param name="limit" as="xs:integer" select="127"/> <xsl:template match="Artists">...

How to increment date and time in XSLT 2.0

xml,xslt,xslt-2.0

try with this stylesheet: <?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"> <xsl:strip-space elements="*"/> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:template match="rootElement"> <xsl:element name="TransformDate"> <xsl:value-of select="xs:dateTime(TestDate) + xs:dayTimeDuration('P1D')"/> </xsl:element> </xsl:template>...

Use XSLT 2.0 to display an image from a directory

xml,xslt-2.0

Figured this one out on my own. Here's what I did. I created a DOCX file with just the image in the body of document. I then created a bookmark with the image highlighted and named the bookmark "logo". I saved the DOCX file to C:\images\logo_template.docx I then went into...

How to group the elements in XSL?

xslt-2.0

Here is a sample stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="p[@class = 'Reference_Unnum']"> <reference> <xsl:for-each-group select="span" group-by="(@dir, @class)[1]"> <xsl:choose> <xsl:when test="current-group()[2]"> <xsl:element name="{lower-case(@dir)}s"> <xsl:for-each-group select="current-group()" group-starting-with="span[@class...

Super-efficient way to report on whether or not there are fiction books costing more than $10

xml,performance,xslt,xslt-2.0,processing-efficiency

I want the template to output false if: There are fiction Books that cost greater than $10.00 How about: <xsl:template match="/Books"> <xsl:value-of select="not(Book[Genre='Fiction']/Cost >10)" /> </xsl:template> Note that the output is not XML....

XSLT Sequence Number Generation

java,xslt,xslt-2.0,xslt-grouping

Assuming you use for-each-group then outputting and formatting the position() should suffice: <xsl:template match="/"> <xsl:for-each-group select="city/family" group-by="parent"> <xsl:value-of select="concat(format-number(position(), '00'), ' ', current-grouping-key(), '&#10;')"/> </xsl:for-each-group> </xsl:template> ...

how to compare and get result from multiple source matching and conditional result to target

xml,xslt,xslt-2.0,jdeveloper,bpel

I could not understand your XSLT at all. Hanging onto this explanation: Explanation: if system number is same and id has changed. I need to update id. if there is any extra system added in first xml I need to add it in target xml. I believe you want to...

HashMap iteration in XSLT 2.0

java,xml,xslt,xslt-2.0,xsl-fo

What you would need to do is add a second xsl:for-each to loop over each string and create the fo:table-cell's from that. <xsl:for-each select="remarksMap/entry"> <fo:table-row> <xsl:for-each select="string"> <fo:table-cell padding="3px" text-align="left"> <fo:block font-size="7pt"> <xsl:value-of select="."/> </fo:block> </fo:table-cell> </xsl:for-each> </fo:table-row> </xsl:for-each> You could also use a push style approach... XSLT 2.0 <xsl:stylesheet...

unable to match a pattern though declared

xslt,xslt-2.0

Calling a named template does not change the context. I am not sure why you need the named template, but if you must, change it to: <xsl:template name="pageCount"> <div class="number"> <xsl:value-of select="(//page/@number)[1]"/> </div> </xsl:template> Updated demo: http://xsltransform.net/nc4NzQj/1...

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

xml,xslt,xslt-2.0,saxon

XPath 2.0 has operators << and >> so your first question would translate into //node()[. >> $pb1 and . << $pb2] (within XSLT code you need to escape << as &lt;&lt;, e.g. //node()[. >> $pb1 and . &lt;&lt; $pb2]). Selecting a pb element by its @n attribute should be obvious:...

Why are fn:matches and fn:replace throwing parse errors in XSLT 2.0?

java,xml,xslt,xslt-2.0

Oracle's XML Developer's Kit (12c Release 1) only partially supports XSLT 2.0. Unfortunately, fn:matches and fn:replace are not supported: Some features of these specifications are not supported in the current release: The Schema Import and Static Typing features are not supported, but the XML Schema built-in types specified by the...

How do I assign the text of HTML Elements to a XSLT Variable?

html,xslt-2.0

If you want to map each row to a result document then I suggest to write a template <xsl:template match="tr"> <xsl:result-document href="out{td[1]}.html"> ... </xsl:result-document> </xsl:template> then make sure there is an apply-templates for the parent table that makes sure the tr elementd are processed....

XML-XSLT-XPATH : How to convert multiple XML elements to a string, separated by semicolon

xml,xslt,xpath,xslt-2.0

you could use something like: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>UserNames: &quot;</xsl:text> <xsl:value-of select="/Users/user/username" separator=";"/> <xsl:text>&quot;&#xA;</xsl:text> <xsl:text>Names: &quot;</xsl:text> <xsl:value-of select="/Users/user/name" separator=";"/>...

XSLT convert xml block under a specific node to xml-escaped content of that node

xslt,escaping,xslt-2.0,cdata

Here is a suggestion using XSLT 3.0 as supported by Saxon 9.6 HE, PE and EE: <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="div"> <xsl:copy> <xsl:apply-templates mode="serialize"/> </xsl:copy> </xsl:template> <xsl:template...

Split the equation based on first dot (.)

xml,xslt,xslt-2.0

Looking at the answer to the previous question, provided by michael.hor257k, there are a couple of key differences to the XSLT you are using in this question. In the previous answer, which splits on comments, it iterates the number of times such comments appear <xsl:for-each select="0 to count(//comment()[.='Break'])"> So, in...

How to subtract 1 day (calculate day before) in XSLT 2.0?

xml,xslt,xslt-2.0

Given your input XML, this XSLT transformation: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="vToday" select="/objects/LastRunTime__c/Last_Run_Time__c" as="xsd:dateTime"/> Today is: <xsl:value-of select="$vToday"/> 1 day ago it was: <xsl:value-of select="$vToday - xsd:dayTimeDuration('P1D')"/>...

Sorting elements in XSLT 2.0

xml,sorting,xslt,xslt-2.0

Sorry, if this is a very simple question. No, this is not simple at all. Try it this way: XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:variable name="sorted-names"> <xsl:perform-sort select="/root/Name"> <xsl:sort select="."/> </xsl:perform-sort> </xsl:variable> <!-- identity transform --> <xsl:template match="@*|node()">...

Group a number of template matches without a parent element in XSLT 2

xml,xslt,xslt-2.0

An interesting and well-asked question! Change the template that matches / to <xsl:template match="/article"> <impactStatements> <xsl:for-each select="informaltable"> <statement> <xsl:apply-templates select=". | following-sibling::*[self::para][1]"/> </statement> </xsl:for-each> </impactStatements> </xsl:template> The result is: <?xml version="1.0" encoding="UTF-8"?> <impactStatements> <statement> <Assisted>Lorem ipsum dolor sit amet.</Assisted>...

Using a variable in group-starting-with

xslt,xslt-2.0

You need to make sure you process the items once the grouping is done so use <xsl:apply-templates select="current-group()"/> in the xsl:otherwise: <xsl:template name="nest_headings"> <xsl:param name="working_group"/> <xsl:param name="heading_level"/> <xsl:variable name="heading_name" select="concat('head', $heading_level)"/> <xsl:if test="$heading_level &lt; 6"> <xsl:for-each-group select="$working_group" group-starting-with="*[local-name() eq $heading_name]"> <xsl:choose>...

Memory efficient XSLT for transforming large XML files

xml,xslt,out-of-memory,xslt-1.0,xslt-2.0

Lingamurthy CS, Please, add the <xsl:strip-space elements="*"/> declaration, which you removed from the original solution. This strips from the source XML document any whitespace-only text node. Not stripping these nodes may significantly increase the number of nodes and the memory to hold them -- in your case, the required memory...

XSLT - Put Content by checking attribute

xml,xslt,xslt-2.0

Well, I think we still don't have a full specification, but I'll try. I think you've told us (a) add a new node after any sec with @sec_type='scope'. That's <xsl:template match="sec[@sec_type='scope']"> <xsl:copy-of select="."/> <c type="newaddingnode">&#x200B;</c> </xsl:template> (b) add a new node after any sec with @sec_type='norm-refs'. That's <xsl:template match="sec[@sec_type='norm-refs']"> <xsl:copy-of...

How to find first occurence of particular text within element

xml,xslt,xslt-2.0

The first part of this problem is to identify the first descendant text node in each para that contains "text1". Once that node is identified it's a simple matter of substring-before and substring-after: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|node()"> <xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy> </xsl:template> <xsl:template match="text()[. is (ancestor::para[1]//text()[contains(., 'text1')])[1]]"> <xsl:value-of...

Replacing XPath Expression with Variable/Function

xslt,xpath,xslt-2.0

You can use substring(*[local-name() = $var1], 1, $var2) where you then bind var1 as 'date' and the other variable with a number value.

XSLT template not applying to newly-created elements

xml,xslt,xslt-2.0,saxon

You would need to capture the nodes created by the analyze-string into a variable and then apply templates to them. You can use template modes to avoid infinite recursion. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xpath-default-namespace="http://www.w3.org/1999/xhtml" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:epub="http://www.idpf.org/2007/ops"> <xsl:output method="xhtml" encoding="utf-8"...

Which way of writing this sum of attribute values is better?

xpath,xslt-2.0

You can use sum(a/b/(@x, @y)).

match cases based on range with alphabets

xslt,xslt-2.0

With XSLT 2.0 you can use regular expressions so for the alphanumeric case you can use <xsl:template match="para[matches(., '^39[A-P]$')]">case1</xsl:template> and a simple number comparison for the second case <xsl:template match="para[. ge 72 and . le 85]">case2</xsl:template> ...

Remove XML Node text using XSLT

xml,xslt,xslt-2.0

Here's one way: <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:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="c"> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet> Here's another:...

count the nodes ignoring blank nodes

xslt,xslt-2.0

How about .... <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> <xsl:output method="html" doctype-public="XSLT-compat" encoding="UTF-8" indent="yes" /> <xsl:strip-space elements="*" /> <xsl:variable name="FinalChap"> <xsl:value-of select="format-number( xs:integer( substring-before((/body/nd/pnn)[1],'.')), '00')"/> </xsl:variable> <xsl:template match="/"> <html> <head><title>New Version from...

How to use a parameter in a for-each loop xsl

xml,xslt,parameters,foreach,xslt-2.0

You don't necessarily need to use xsl:for-each here, but if you want, you could do: XSLT 2.0 <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 method="text" encoding="utf-8"/> <xsl:decimal-format decimal-separator="," grouping-separator="."/> <xsl:param name="matrikelnummer" select="2354444"/> <xsl:template match="/unidatenbank"> <xsl:for-each...

converting xml to html table cannot get it right

html,xml,xslt,xslt-2.0

Change <xsl:for-each select="(Generated/Employees/Employee)/Sales/Sale"> <tr> <td> <xsl:value-of select="@value"/> </td> </tr> </xsl:for-each> to <xsl:for-each select="Generated/Employees/Employee"> <tr> <xsl:for-each select="Sales/Sale"> <td> <xsl:value-of select="@value"/> </td> </xsl:for-each> </tr> </xsl:for-each> ...

Not able to form xpath using mule expression for given xml

xml,xpath,mule,xslt-2.0,esb

Well I am able to extract the value using XPATH ... You can do it 2 ways :- 1) First way is using local-name and without namespace :- <logger message="Value of id : #[xpath://.[xpath:local-name()='ID']]" level="INFO" doc:name="Logger"/> It works perfect and it is simple, but the XPATH is an old way...

Type error when using as=“element” on a variable

xml,xslt,xslt-2.0

Well with Saxon EE you have full access to XSLT 3.0 or to Saxon's extension functions http://saxonica.com/html/documentation/functions/saxon/parse.html so I would simply parse the result with e.g. <xsl:variable name="result" select="saxon:parse(MyServiceResult)" xmlns:saxon="http://saxon.sf.net/"/>. That would give you a document node you can then output its contained nodes, e.g. <xsl:copy-of select="$result/node()"/>.

using a counter for all groups members in for-each-group

xml,xslt,xslt-2.0

You could do it in two stages - first re-order the whole unpaginated list of entries so they are grouped together by key (i.e. in the order that the final output requires), then take the appropriate page "slice" of that sequence to do the actual transformation: <xsl:variable name="orderedEntries" as="element()*"> <xsl:for-each-group...

Creating alphabetical index with fixed number of columns in XSLT 2.0

xml,xslt,xslt-2.0,xslt-grouping

I came up with <?xml version="1.0" encoding="UTF-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:param name="size" select="3"/> <xsl:template match="countries"> <xsl:copy> <xsl:variable name="groups"> <xsl:for-each-group select="country" group-by="substring(name, 1, 1)"> <xsl:sort select="current-grouping-key()"/> <xsl:element name="{current-grouping-key()}"> <xsl:copy-of...

Creating structured documents using nested XSLT2 grouping

html,xslt-2.0

Either write a recursive function doing the grouping for each level or nest the for-each-group elements: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" xmlns="http://www.w3.org/1999/xhtml" xpath-default-namespace="http://www.w3.org/1999/xhtml" version="2.0"> <xsl:output method="xhtml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy>...

How to enumerate a table sequentially

xslt,xslt-2.0

Your example is not a good one. If your input looks something like: <root> <table id="table1"> <title>Title 1</title> </table> <not-table/> <table id="table2"> <title>Title 2</title> </table> <not-table/> <table id="table3"> <title>Title 3</title> </table> </root> then applying: <xsl:template match="/root"> <xsl:copy> <xsl:apply-templates select="table"/> </xsl:copy> </xsl:template> <xsl:template...

Use XSLT to mark up text matching regex?

xml,xslt,unicode,xslt-2.0,saxon

I came up with http://xsltransform.net/jyH9rMo which just does <?xml version="1.0" encoding="UTF-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <hmtl> <head> <title>New Version!</title> </head> <xsl:apply-templates/> </hmtl> </xsl:template> <xsl:template match="@*|node()">...

how to fetch data from one XML group of elements and feed onto another XML group

xslt,xslt-1.0,xslt-2.0,xslt-grouping,exslt

What you want to do here is lookup a value from a matching node in the external file. You didn't say so, but I presume the matching node is the one where the PN value matches the local pNumber. 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:strip-space...

XSLT 2.0 for-each-group, sum based on parent value

xslt,xslt-2.0,xslt-grouping

The problem is that for the case where the area attribute is "area1", there are only two price nodes involved. The sum function will not sum the same node more than once. (Change sum to count and you will see it return 2). Try changing the statement to this instead...

How to use param variables while creating xml using xslt

xml,soap,xslt-2.0

What you're looking for is an Attribute Value Template (AVT)... <cs:User EmployeeId="{$EmployeeID}"> ...

How to print element tags in XML document using XSL

xml,xslt,xslt-1.0,xslt-2.0

Strictly speaking, you actually be getting an error when you run the output, as because MathiasMuller says in comments, xsl:element must not be a top-level element (i.e it cannot be a direct child of xsl;stylesheet). I am guessing Ecplise may just be ignoring that. If you are, however, getting only...

XSLT dynamic element selection

xslt-2.0

Define the variable as <xsl:variable name="controlList" select="'name', 'address', 'phone'"/>, then yo can use M[@N = $controlList]/@V. See http://xsltransform.net/6qVRKw1 for an example. If you can't set up the first variable as a sequence of strings then compute a second e.g. <xsl:variable name="controlList">name,address,phone</xsl:variable> <xsl:variable name="controlSeq" select="tokenize($controlList, ',')"/> and then you can also...

Replace all tags below a node

xslt-1.0,xslt-2.0

If you use match="/*//*" then you match all descendant elements of the root element. Then you can construct a new element using <xsl:template match="/*//*"><xsl:element name="local-name()"><xsl:apply-templates select="@* | node ()"/></xsl:element></xsl:template> Then add the identity transformation template to your code and you are done....

xsl:choose Expression must evaluate to a node-set

c#,xml,xslt,xslt-2.0,xsl-choose

XSLT 1.0 has the union operator | which works on node-sets and the boolean or operator which works with boolean values. There is no || operator in XSLT, neither in 1.0 nor in 2.0. If you want to write a boolean or expression use <xsl:when test="Key='Seller count' or Key='Buyer count'">...

Apply XSLT on an XmlDocument and get the updated XmlDocument

c#,xml,xslt,xslt-2.0

If you want to use a System.Xml.XmlDocument with the current XSLT 1.0 implementation (XslCompiledTransform) that Microsoft offers then you can use XmlDocument resultDocument = new XmlDocument(); using (XmlWriter xw = resultDocument.CreateNavigator().AppendChild()) { XslCompiledTransform proc = new XslCompiledTransform(); proc.Load("myXsl.xsl"); proc.Transform(sourceDocument, null, xw); xw.Close(); } return resultDocument; ...

How to transform change comment using xslt

xml,xslt,xslt-2.0,xpath-2.0

You can use the following XSLT: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | *"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()[contains(.,'α-index')]"> <xsl:value-of select="replace(., 'α-index', 'index 1')"/> </xsl:template> <xsl:template match="comment()">...

How to group flat xml into 2 levels in xslt 2.0

xml,xslt,xslt-2.0,xslt-grouping

Nest two for-each-group: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="world"> <xsl:copy> <xsl:for-each-group select="country" group-by="category[@scheme = 'level1']/@type"> <xsl:element name="{current-grouping-key()}"> <xsl:for-each-group select="current-group()[category[@scheme = 'level2']]" group-by="category[@scheme =...

Preserving entity references when transforming XSLT with XSLT

xml,xslt,xslt-2.0

Try <xsl:output encoding="us-ascii"/>, which will force all non-ASCII characters to be serialized using hex or decimal character references, whether they started life that way or not.

XSLT 2.0 Compare sequence of attribute values to variable

xml,xslt,xslt-2.0

This is all a bit abstract, but to demonstrate a principle, let us have the following: XML <root> <elem attr1="alpha charlie" attr2="delta alpha echo" attr3="foxtrot bravo golf"/> <elem attr1="alpha charlie" attr2="hotel delta" attr3="bravo india"/> </root> XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:variable name="values" select="('alpha', 'bravo')"/> <xsl:template...

Condition getting getting called where it is not supposed to be

regex,xslt,xpath,xslt-2.0

Looking at your current XSLT, at the moment when you apply your regex (with analyze-string) you are positioned on a para element, not a content-style, and so doing select="." will get the string value of the entire para element, not just the first node. What you may need to do...

Unkown system function: format-date in XSLT

xslt,xml-parsing,xslt-1.0,xslt-2.0

As per the error, it looks like you are using unsupported version of validation engine. Please choose Saxon-HE/PE/EE 9.5.1.7 instead of Saxon6.5.5 If you are using eclipse or Oxygen editor, you can find this settings under preferences > XML > XSLT-FO-XQuery. In Oxygen editor, you can choose engine from drop-down...

Is it possible to preprocess xml source within the same XSLT Stylesheet?

xslt,xslt-2.0

Yes it is possible. One possibility would be to to proceed as follows: <xsl:template match="/"> <!-- store the modified content in a variable --> <xsl:variable name="preprocessed.doc"> <xsl:apply-templates mode="preprocess" /> </xsl:variable> <!-- process the modified contents --> <xsl:apply-templates select="$preprocessed.doc/*" /> </xsl:template> <!-- first pass: sample process to add an attribute named...

Apply xslt tokenize function to results of apply-templates

xml,xslt,xslt-2.0

I need to be able to reduce it to just the plaintext: "of right hool herte & in oure best entent," and then tokenize on the space to get a list of either comma or tag-separated values. Not sure what "tag-separated values" means. Given the following test input: XML...

how to remove specific elements but not the text inside it using xslt

xml,xslt,xslt-2.0

<xsl:template match="//para"> <xsl:copy> <xsl:value-of select="."></xsl:value-of> </xsl:copy> </xsl:template> (or to avoid white space from other child elements: <xsl:template match="//para"> <xsl:copy> <xsl:value-of select="./*/*/text()"></xsl:value-of> </xsl:copy> </xsl:template> ...

making a transformed element the child of a sibling

xml,xslt,xslt-2.0

You are referring to a namespace, but did not declare this namespace in your input XML. I assume it is a default namespace: XML Input <?xml version="1.0" encoding="UTF-8"?> <OAI-PMH xmlns="http://www.loc.gov/mods/v3"> <metadata> <mods> <genre>Negatives (photographic)</genre> <genre>Cellulose nitrate film</genre> <physicalDescription> <form>Photograph</form> </physicalDescription> </mods> </metadata> </OAI-PMH> In the stylesheet you posted, there are...

Nested grouping elements using XSLT

xml,xslt,xslt-2.0

If you want to group, why don't you use the proper grouping tool? XSLT 2.0 <xsl:stylesheet version="2.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="/toc"> <toc> <!-- PRELIMS --> <div class="prelims"> <xsl:copy-of select="toc.entry[@level='prelims']"/> </div> <!-- PARTS --> <xsl:for-each-group select="toc.entry[not(@level='prelims' or @level='endmatter')]"...

xslt resolve hierarchy and copy into new document

xml,xslt,xslt-2.0

If I understand this correctly, it should be quite easy to do using keys: XSLT <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="node-by-id" match="node" use="@id" /> <xsl:key name="noderef-by-id" match="noderef" use="@id" /> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/>...

Flatten child elements nested within text nodes

xml,xslt,xslt-2.0

Trying to treat it as a grouping problem I came up with <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:param name="prefix" select="'target-'"/> <xsl:output indent="yes"/> <xsl:template match="document"> <xsl:copy> <xsl:for-each-group select="descendant::text()[normalize-space()]" group-adjacent="generate-id(ancestor::div[starts-with(@class, $prefix)][1])"> <xsl:apply-templates select="ancestor::div[starts-with(@class, $prefix)][1]" mode="g">...

Using XSLT variable in X PATH string

xslt,xslt-2.0

You can refer to the variable anywhere in the XPath expression: /results/server[@name eq $server] If you write it with quotes, '$server', then it is just a string literal that happens to contain a dollar sign....

XSLT - Why are multiple nodes getting merged in the output ( Group By)

xslt,xslt-2.0

Inside of your bework variable you create a berow element for each Transaction group but then you use <xsl:for-each select="current-group()"> to output a begin-date for each Transaction in that group, without structuring or wrapping them further. With your input that means that berow element can contain two or three begin-date...

Comparing a sequence of elements and replacing on match via XSLT/Xpath

xml,xslt,xpath,xslt-2.0

Starting from the context of one particular old/xref you can check for a matching new one with <xsl:variable name="matching" select="../../new/xref[. = current()]"/> In the square brackets, . is the new/xref you're testing and current() is the old/xref you started from. Checking whether this sequence is empty tells you whether or...

Using XSLT to recursively load relative XML files and apply transformation

java,xml,xslt,xslt-2.0

The XSLT document function in XSLT 1.0 and in XSLT 2.0 additionally the doc function allow you to pull in further documents, processing is then simply possible with matching templates. So consider to move your XSLT coding style to write matching templates and apply-templates, then you can easily do <xsl:template...

Multiple conditions in XSLT

php,xml,xslt,xslt-2.0

A variation on Martin Honnen's solution, with slightly more code reuse, is <xsl:template match="demands/demand"> <tr> <xsl:attribute name="class"> <xsl:apply-templates select="@category"/> </xsl:attribute> <xsl:apply-templates/> </tr> </xsl:template> <xsl:template match="@category[. = 'Movie']" >info</xsl:template> <xsl:template match="@category[. = 'Tv show']" >danger</xsl:template> <xsl:template match="@category[. = 'Music']"...

Similar type of data not matching the same case

xpath,xslt-2.0

If you don't want the first paragraph only, don't request it. para[content-style[matches(., '(\w+)/(\w+)')]][1] ^ | here Remove the quantifier and insert it into another expression as indicated: contains(substring-after(substring-after(./content-style[1]/text(),'/'),'/'),' ') ^ | here ...

XSLT 2.0 using xsl copy/copy-of in for-each, overwriting certain attributes

xml,xslt,xslt-2.0

This worked for me: <xsl:template match="someElement"> <xsl:for-each select="key('keyname', concat(@id, '+', @folder), $reuseFile)/child::*"> <xsl:copy> <!-- overwrite attribute --> <xsl:attribute name="rev" select="@ver"/> <!-- exclude certain attributes --> <xsl:copy-of select="@*[fn:local-name() != 'somename']"/> <xsl:apply-templates select="node()"/> <!-- chooses the template below --> </xsl:copy> </xsl:for-each> </xsl:template> <xsl:template match="abc |...

Adjust an alphabetical index from xml grouping to make columns equal

xml,xslt,xslt-2.0,xslt-grouping

I would suggest the following approach: XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:param name="columns" select="3"/> <xsl:template match="/countries"> <xsl:variable name="indexed-countries"> <xsl:for-each select="country"> <xsl:sort select="."/> <country index="{position()}"> <xsl:copy-of select="@*|*"/>...

Why is xsl:when not working as expected?

xml,xslt,xslt-2.0

If possible can you show how we can Implement this expected output in xsl:choose? To implement this using xsl:choose you could do something like: <xsl:template match="source"> <div> <xsl:apply-templates/> </div> </xsl:template> <xsl:template match="source/*"> <xsl:choose> <xsl:when test="self::bold"> <p><b><xsl:apply-templates/></b></p> </xsl:when> <xsl:when test="self::italic"> <p><i><xsl:apply-templates/></i></p>...