xslt

How to preserve XML namespace in XSLT output?

XSL stylesheet should output following code to Internet Explorer: <xml:namespace prefix="vml" ns="urn:schemas-microsoft-com:vml"/> But when I execute following template with any XML <xsl:template match="*|node()"> <xml:namespace prefix="vml" ns="urn:schemas-microsoft-com:vml"/> </xsl:template> IE throws parsi...

Using EXSLT to subtract dates

How can I use EXSLT extensions to subtract a date. I see that there is a date-add function, but the EXSLT docs don't include any examples. I am trying to take the current date and subtract 1 month for example. ...

xsl:choose & xsl:when

If I am testing several different defined parameters can I call multiple xsl:when statements within on xsl:choose statement? So if I have: <parameters> <param id="1"> <key>Load</key> <value>XML</value> </param> <param id="2"> ...

XSL Transform remove Xml Elements

I am stumped. Given an xml doc like: <Frag> <DirRef Id="BeemzDir"> <Com Id="BEED24F05AB78FB588F61D4092654B6D" Guid="{A11AB356-2F45-4157-92EF-ED49F5BE0F70}"> <FileName Id="fil1" KeyPath="yes" Source="My.Exe" /> </Com> <Com Id="FFF24F05AB78FB588F61D4092654CCC" Guid="{A11AB356...

xslt problem (namespaces?)

I have a document like this: <?xml-stylesheet type="text/css" href="http://ltw1001.web.cs.unibo.it/svg.css" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg= "http://www.w3.org/2000/svg"&gt; <body> <sv...

How to make a node result be diferent depending on the existance of a certain node using XLST?

My system produces a XML that contain a node that, depending on the type of event, came with different name. The name can be <floatRate> or <fixedRate>. The path is always the same, only the node name that is different. I need a transformation that can populate one field based on that name. The field will be called <type> and the conten...

XSL for converting all rows and columns of XSL for Export to Excel. dynamic looping

Hi, I have an xml resultset which has to be converted using XSL for display into an excel spreadsheet in a vb.net application. The xml resultset has 15 columns (15 properties of client like firstname,lastname,address etc) and I don't want to hardcode the select attribute of xsl/xpath with property or xml element names. I need an XSL tha...

Use XSLT to remove any duplicate nodes only when they contain the same content

Hi, I have the following xml: <?xml version="1.0" encoding="UTF-8"?> <SomeName> <NodeA> DataA </NodeA> <NodeA> DataB </NodeA> <NodeA> DataA </NodeA> <AnotherNode> DataA </AnotherNode> <AnotherNode> DataC </AnotherNode> <AnotherNode> DataC </AnotherNode> <SingleNode>...

XSLT character padding for European characters to fixed width output.

I've got a requirement to take some XML and transform it into a fixed-width load file for loading to an SAP system. My algorithm works fine except for some weird European characters such as Ã, which, when in a string returns a string length of +1 for each instance of the char. So for example the text Ãbcd would have a string-length($va...

How can I use annotations in XSD to map XML integers to the related descriptions?

I am writing an XSLT for turning an XML file into a human-readable HTML page. The XML has several fields to describe some aspects of the data, which contain integers which represent mapped strings. The integers are not the information the user wants, I need to map those integers to the corresponding strings. The mapped strings are avai...

XSLT - nested loop

Hi I'm having trouble with an XSLT to loop through all the rows, and then all the columns in each row element. So if this is the XML I have: <root> <subelement> <rows> <row title="Row1"> <column title="A" /> <column title="B" /> </row> <row title="Row2"> <column title="C" /> <column title="D" /> </row> </rows> </subelement> </...

Converting XML files to be human-editable and managable by VCS

Sometimes XML files needs to be stored in some VCS. Such files are often edited using GUI tools which can reorder the elements each times as they want. Also VCS merging is usually line-oriented, and often XML files either looks likes one long line or fully indented like <foo> <bar> <name> n3 </name> ...

nested <xsl:if> & <xsl:when>

Can you nest xsl:if within nested xsl:when, for example: <xsl:choose> <xsl:when test="param/@id = '1' " > <xsl:if test="param/value = 'XML' "> <xsl:when test="param/@id = '2' "> <xsl:if test="param/value = 'HTTP' "> <xsl:when test="param/@id = '3' "> ...

XSLT Replace Element Text with Enclosed Text Value

What XSLT is required to replace the text of a node with the same text enclosed in double quotes: <users> <user_info> <lastname>Jenkins</lastname> <firstname>Bob</firstname> </user_info> <user_info> <lastname>Smith</lastname> <firstname>Mike</firstname> </user_info> </users> This is a simplified view, my user_i...

How would I get this odd table from XSLT?

Using this input XML: <?xml version="1.0" encoding="utf-8"?> <Employees> <Employee ID="1"> <FirstName>Klaus</FirstName> <LastName>Salchner</LastName> </Employee> <Employee ID="2"> <FirstName>Peter</FirstName> <LastName>Pan</LastName> </Employee> </Employees> How would you get this output: <Employee...

How to read Date from an XML file and Parse it using XSL

The xml file is having the following structure <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="TestFile.xsl"?> <RootElement> <Date FileModified="7/2/2010 12:54:53 PM" /> <Child Name="A"/> <Child Name="B"/> <Child Name="C"/> <Child Name="D"/> <Child Name="E"/> </RootElement> I need to rea...

XSLT conditions / variable scope

<xsl:choose> <xsl:when test="long convoluted expression"> <xsl:element name="Class">123</xsl:element> <a lot more xsl:elements> </xsl:when> <xsl:when test="next very long expression"> <xml:element name="Class">124</xsl:element> <a lot more xsl:elements> </xsl:when> <tens of more similar...

How do I get all sub-nodes of an XML document?

I have an XML document that models this hierarchy of tasks: 1 Customer 1.1 Product A 1.1.1 Task Alpha 1.1.2 Task Beta 1.2 Product B 1.2.1 Task Alpha 1.2.2 Task Gamma 2 Customer 2.1 Product W 2.1.1 Task Delta Unknown number of Customers, Products, and Tasks per product. There can also be an unknown number of subtasks, ...

Associate an XML-Stylesheet with an XML Document with Nokogiri

Is it possible to associate a stylesheet with with Nokogiri, to create this structure? <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="http://www.my-site.com/sitemap.xsl"?&gt; <root> ... </root> ...

XSLT: Define a param with & ampersand

Hi, I need to define a xsl:param with a string that contains & character for further processing. For example: <xsl:param name="greeting" as="xs:string">Hi & Bye</xsl:param> Important Notice: I am using a xslt converter component in a webservice tool. What I do, is that I just initialize the param and as the webservice is called the...