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...
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>...
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...
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...
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>...
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> ...
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.
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...
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 '), ., '
')"/> </xsl:template> <xsl:template...
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> ...
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...
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...
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...
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>...
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...
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...
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....
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...
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>...
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...
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()]"/>...
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> ...
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...
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...
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...
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">...
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>...
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...
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...
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....
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(), ' ')"/> </xsl:for-each-group> </xsl:template> ...
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...
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...
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...
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 <<, e.g. //node()[. >> $pb1 and . << $pb2]). Selecting a pb element by its @n attribute should be obvious:...
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...
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....
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: "</xsl:text> <xsl:value-of select="/Users/user/username" separator=";"/> <xsl:text>"
</xsl:text> <xsl:text>Names: "</xsl:text> <xsl:value-of select="/Users/user/name" separator=";"/>...
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...
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...
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')"/>...
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()">...
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>...
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 < 6"> <xsl:for-each-group select="$working_group" group-starting-with="*[local-name() eq $heading_name]"> <xsl:choose>...
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...
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">​</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...
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...
You can use substring(*[local-name() = $var1], 1, $var2) where you then bind var1 as 'date' and the other variable with a number value.
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"...
You can use sum(a/b/(@x, @y)).
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> ...
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:...
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...
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...
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> ...
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...
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()"/>.
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...
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...
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>...
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...
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()">...
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...
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...
What you're looking for is an Attribute Value Template (AVT)... <cs:User EmployeeId="{$EmployeeID}"> ...
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...
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...
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....
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'">...
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; ...
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()">...
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 =...
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.
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...
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...
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...
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...
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...
<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> ...
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...
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')]"...
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()"/>...
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">...
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....
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...
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...
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...
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']"...
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 ...
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 |...
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="@*|*"/>...
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>...