XSLT - Removing CDATA without disabling output escaping - xslt-2.0

Having a bit of an issue with CDATA. For my current project, I had to convert a number of HTML elements into CDATA in order to be imported to a test case management system via XML. I am now tasked with exporting that data and translating it into DITA. The following is an excerpt from the data I am working with that I think provides enough context:
<tr:testopia><tr:testplan><tr:testcase>
<tr:text version="1">
<tr:author>bugzilla</tr:author>
<tr:action><![CDATA[<ol xmlns="http://www.w3.org/1999/xhtml">
<li>
<p xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:cln="http://clean/" class="Table">Refer to
<span style="color:red">CHM795_Workflow_DITA_Test_plan.doc
</span>
</p>
</li>
</ol>]]></tr:action>
<tr:expected_result><![CDATA[<ol xmlns="http://www.w3.org/1999/xhtml">
<li>
<p xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:cln="http://clean/"
class="Table">All requirements are met & example example</p>
</li>
</ol>]]></tr:expected_result>
<tr:setup><![CDATA[]]></tr:setup>
<tr:breakdown><![CDATA[]]></tr:breakdown>
</tr:text>
</tr:testcase></tr:testplan></tr:testopia>
To do this, I need to get the elements previously kept in CDATA out again, and I've found from a small amount of research that a line such as the following will achieve this:
<xsl:template match="tr:text">
<prerequisites>
<xsl:apply-templates select="tr:setup"/>
</prerequisites>
<postrequisites>
<xsl:apply-templates select="tr:breakdown"/>
</postrequisites>
<process>
<actions>
<xsl:apply-templates select="tr:action"/>
</actions>
<results>
<xsl:apply-templates select="tr:expected_result"/>
</results>
</process>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)" disable-output-escaping="yes"/>
</xsl:template>
This will provide me with the following:
<case>
<prerequisites/>
<postrequisites/>
<process>
<actions><ol xmlns="http://www.w3.org/1999/xhtml"> <li> <p xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:cln="http://clean/" class="Table">Perform <span style="color:red">ASM Test Document.docx</span> </p> </li> </ol></actions>
<results><ol xmlns="http://www.w3.org/1999/xhtml"> <li> <p xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:cln="http://clean/" class="Table">Test plan successfully completed</p> </li> </ol></results>
</process>
The issue I currently face is this: disabling output escaping gets me the format I need, translation has worked fine and the DITA file validates. However, in some of these test cases, the content of the HTML elements sometimes contain characters such as &. When I try to translate these cases into their final form after this stage, I receive an error like the following when running with SAXON:
Error reported by XML parser: The entity name must immediately follow
the '&' in the entity reference.
Is there a way I can keep the internal text of the nodes in their current "harmless" state and still wrap it in the nodes also held in CDATA? Could probably phrase that better, but the words aren't coming to mind.

Related

what does 'pop' means in a xslt example on w3.org

the code is a example in second from last:"Example: Output Hierarchic Section Numbers",
https://www.w3.org/TR/2017/REC-xslt-30-20170608/#accumulator-examples
<xsl:accumulator name="section-nr" as="xs:integer*"
initial-value="0">
<xsl:accumulator-rule match="section" phase="start"
select="0, head($value)+1, tail($value)"/>
<xsl:accumulator-rule match="section" phase="end"
select="tail($value) (:pop:)"/>
</xsl:accumulator>
<xsl:template match="section">
<p>
<xsl:value-of select="reverse(tail(accumulator-before('section-nr')))"
separator="."/>
</p>
<xsl:apply-templates/>
</xsl:template>
What does the word ":pop:" in the second "xsl:accumulator-rule" means, Is it a key word or something defined ? thanks
That is an XPath comment which is a string that is delimited by the symbols (: and :)
Have a look at "5.5.2 Syntax of Patterns" of the link you provided:
https://www.w3.org/TR/2017/REC-xslt-30-20170608/#pattern-syntax

XSLT: How to access elements of type both namespace and without namespaces within same article

Please suggest to access the elements which are not having any namespaces. However my code able to access and alter the nodes (elements) which are having namespaces. I am using XSLT2 version. Find my xml (I used DTD path mapped to my local path, please suggest also for access the XML without DTD help.
InPut XML:
<!DOCTYPE article PUBLIC "-//ES//DTD journal article DTD version 5.2.0//EN//XML" "D:/DTDs/Els-parser/art520.dtd">
<article>
<fm>
<ce:title>The title</ce:title>
<ce:author-group>
<ce:author><ce:surname>Rudramuni</ce:surname><ce:given-names>TP</ce:given-names></ce:author>
</ce:author-group>
</fm>
<body>
<ce:sections>
<ce:section>
<ce:section-title>The first Head</ce:section-title>
<ce:para>Tha first para</ce:para>
</ce:section>
</ce:sections>
</body>
<back>
<ref><ce:author>Vijay</ce:author></ref>
</back>
</article>
XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ce="http://www.elsevier.com/xml/common/dtd"
xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
version='2.0'>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="fm">
<xsl:element name="ce:front"><xsl:apply-templates/></xsl:element>
</xsl:template>
<xsl:template match="ce:author">
<xsl:element name="name"><xsl:apply-templates/></xsl:element>
</xsl:template>
</xsl:stylesheet>
Required Result:
<?xml version="1.0" encoding="UTF-8"?>
<article>
<ce:front>
<ce:title>The title</ce:title>
<ce:author-group><name><ce:surname>Rudramuni</ce:surname><ce:given-names>TP</ce:given-names></name></ce:author-group>
</ce:front>
<body><ce:sections><ce:section><ce:section-title>The first Head</ce:section-title><ce:para>Tha first para</ce:para></ce:section></ce:sections></body>
<back>
<ref><name>Vijay</name></ref>
</back>
</article>
But I am getting some extra namespaces like "xmlns="http://www.elsevier.com/xml/ja/dtd" and xmlns="", and some extra attributes are found for some elements like view="all". Thanks in advance. Please suggest.
You seem to ask a lot of questions on XSLT 2.0 recently, which is ok of course, but please kindly consider these guidelines when asking questions:
Use valid examples that we can reproduce your problem with. Your examples, in this and other questions, are not well-formed (missing namespaces in this question for instance), which makes it hard to help you (and they will downvote or close your question, see How to ask).
Tone down the examples to the bare minimum, otherwise people will not run to help you as it is too hard to understand the question asked. In this case, a two-line XML and XSLT would explain your issue.
Run the code you paste here and copy the output (or errors) you get. In this question for instance, the output is not namespace-well-formed, which cannot possibly be the output of any XSLT processor.
To answer your question, you can use a wild-card NameTest, which selects that name in any namespace:
select="*:something"
select="*:foo/*:bar"
select="*:foo[contains(., #*:some-attr)]"

list download files in umbraco 4.11.8

Hi we have created a doc type with a tile, description and an mediaPicker uploadcontrol
Using this we have uploaded a small number of test files. We now want to list the files by title and description (done) and prvide a link which when clicked, directs the browser to upload the file from the node listed. All example we can find are for earlier versions < 4.5
and cant get them to work in 4,11.8....
the line we are having problems with is:
<a href="umbraco.library:GetMedia($currentPage/uploadFile, 'false')/umbracoFile"/>
or
<a href="umbraco.library:GetMedia($currentPage/uploadFile, 0)/umbracoFile"/>
which give a "too big" int32 error
What are we missing please?
Can you try this code:
<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/uploadFile, 0)" />
<xsl:if test="$media">
<xsl:variable name="url" select="$media/umbracoFile" />
<xsl:variable name="width" select="$media/umbracoWidth" />
<xsl:variable name="height" select="$media/umbracoHeight" />
<img src="{$url}" width="{$width}" height="{$height}" />
</xsl:if>
You can find more info on the wiki of Umbraco: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

Umbraco setting image error

in my umbraco setting, i dont have any image logo to upload my image that was saved in my Media folder, only insert umbraco page field and insert umbraco macro logo was there.I tried many links but it was unsuccessful.im using umbraco V3.0.5
If I understand you correctly, you're modifying a template (you have access to insert field and insert macro) and you want to add an image that is saved in your media section.
Are you really using Umbraco 3 - that is a few years old now and the syntax is very different and you will probably need to use xslt; for example inserting a macro will look different on your template for v3 and v4 (v5 has been deprecated and v6 is not live yet).
(http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters/advanced-macro-parameter-syntax)
Umbraco Version 3:
<?UMBRACO_MACRO macroAlias="RenderProperties" pageValue="[#bodyText]" />
Umbraco Version 4:
<umbraco:macro alias="RenderProperties" pagevalue="[#bodyText]" runat="server"/>
In the older versions of umbraco putting an image onto a page from media required writing some xslt and referring to it in a macro - this example (that I've dredged up) would display the image that was picked for a page with an alias of 'imageAliasName'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="mediaId" select="number($currentPage/imageAliasName)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<img>
<xsl:attribute name="src">
<xsl:text>/ImageGen.ashx?image=</xsl:text>
<xsl:value-of select="$mediaNode/umbracoFile"/>
<xsl:text>&width=200</xsl:text>
<xsl:text>&height=200</xsl:text>
</xsl:attribute>
</img>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
in V3 i insert that image in to one of my content file from there i can view the id for my image..using that id image to write my code in my setting..when i write my image logo was viewed successful.

Actual element tags are not getting captured

I am using the below piece of XSL code to construct a span tag calling a javascript function on mouseover. The input to the javascipt should be a html table. The output from the variable "showContent" gives just the text content but not along with the table tags.
How can this be resolved.
XSL:
<xsl:variable name="aTable" as="element()*">
<table border="0" cellspacing="0" cellpadding="0">
<xsl:for-each select="$capturedTags">
<tr><td><xsl:value-of select="node()" /></td></tr>
</xsl:for-each>
</table>
</xsl:variable>
<xsl:variable name="start" select='concat("Tip('", "")'></xsl:variable>
<xsl:variable name="end" select='concat("')", "")'></xsl:variable>
<xsl:variable name="showContent">
<xsl:value-of select='concat($start,$aTable,$end)'/>
</xsl:variable>
<span xmlns="http://www.w3.org/1999/xhtml" onmouseout="{$hideContent}"
onmouseover="{$showContent}" id="{$textNodeId}"><xsl:value-of select="$textNode"></xsl:value-of></span>
Actual Output:
<span onmouseout="UnTip()" onmouseover="Tip('content1')" id="d1t14">is my </span>
Expected output:
<span onmouseout="UnTip()" onmouseover="Tip('<table><tr><td>content1</td></tr>')" id="d1t14">is my </span>
What is the change that needs to done in the above XSL for the table, tr and td tags to get passed?
The concat() function takes the string values of its arguments and concatenates them.
$aTable as defined has no string value.
You may want to define it not as element()* but as xs:string.
Then you'd need to escape the text in it, or to include it in a CDATA tag. Because the value of $aTable is dynamically generated, using CDATA isn't possible.
You'll need your own XML serialization processing to turn all tags markup into text. Even in this case, the contents of the onmouseover attribute will contain escaped characters, due to attribute value normalization.
Seems quite impossible.

Resources