0

I have been using Altova Map Force to build XSL transformations recently, and I have come across an issue. In order to create a valid XML output file (from an input text file, which was simple enough to build), it needs to contain some xmlns attribute tags.

Unfortunately, I cannot find a way to do this validly (modified the output xsd schema def and attribute forcing) within Map Force or my Data Transformation Tool (built by the client I am building this for, based on Saxon). So, my solution is to parse the generated XML into another (final) transformer where the XML Elements of the File are transformed into a single text block that contains a string representation of the XML (i.e. the file string that is returned), then trim off the parent element declaration, and modify it with the amended element (with the xmlns attribute), then output that to save.

I have done some tests, and I can do this validly, but in that test, I was parsing in a pre-converted xml string that had the function applied to it. So, can anyone advise me as to how, within xslt, I can convert a collection of elements into a string that I can modify and return as CDATA (which the transformer program will convert treat as a string and dump it straight into the output file)?

1
  • I too think you should focus on the real issue here ("it needs to contain some xmlns attribute tags"), instead of an overly elaborated workaround. Commented Dec 16, 2013 at 12:21

2 Answers 2

1

The latest version of the Altova product line has support for XPath 3.0 functions like http://www.w3.org/TR/xpath-functions-30/#func-serialize so assuming that all you need is e.g.

<xsl:output cdata-section-elements="foo"/>

<xsl:template match="bar">
  <foo><xsl:value-of select="serialize(.)"/></foo>
</xsl:template>

Saxon's commercial versions also support that function I think (if you use version="3.0" for your stylesheet).

However you might want to post the real problem description (input you have, output you want) in a separate question so that we can see whether you really need to use the approach you have outlined so far to ensure you have certain namespace declarations.

Sign up to request clarification or add additional context in comments.

4 Comments

would love to post the full details, but I might get into a bit of trouble, nda's and that :( But that does sound good, but I have recently updated to the most recent version of Altova Mission Suite (the one released about a month ago), and I cannot find any reference to the serialize function within MapForce. Might it be called something else? Sadly, AFAIK you can only create XSLT from MapForce, not the other way round :(
altova.com says "XPath/XSLT/XQuery 3.0 support" and the documentation of Raptor manual.altova.com/RaptorXML/raptorxmlserver/… says "The XPath and XQuery 3.0 functions and operators support of RaptorXML Server conforms to the World Wide Web Consortium's (W3C's) XPath and XQuery Functions and Operators 3.0 Recommendation of 21 May 2013." and that lists the serialize function. I would assume that MapForce uses Raptor for XSLT and that way should support the function. But I don't use MapForce myself so I have no way to check.
I have just browsed through the MapForce online docs, it indeed seems as if its function support remains restricted to XSLT and XPath 2.0 so my suggestion using serialize might indeed not work.
I did some tests on it, and the engine that the company is using to do the transformations hasn't been updated in a year, so is still using xpath 2, but I have found a work around
0

Success, I had to modify the XSD schema and set the targetNamespace to the same as xmlns in the schema, along with elementFormDefault="qualified", and that has modified the output xml to the appropriate response

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.