Difference output when using XSLT Debugger versus XPath/XQuery Builder

Here should go questions about transforming XML with XSLT and FOP.
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Difference output when using XSLT Debugger versus XPath/XQuery Builder

Post by ann.jensen »

Hi,
I am troubleshooting a transform problem and have tested the XML and XSLT in both Oxygen Editor XSLT Debugger and XPath/XQuery Builder. I am getting different output from each and don't understand why.
Firstly I have applied this XSLT to the XML below

Code: Select all

<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:variable name="topicTitle">
    <xsl:value-of select="*[
    contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]"> 
    </xsl:value-of>
</xsl:variable>

<xsl:template match="*[contains(@class, ' topic/topic ')]">
    <topicTitle>
        <xsl:choose>
        <!--  Investigate: Map's nav title is always up to date. -->
            <xsl:when test="not($topicTitle='')">
                <xsl:value-of select="normalize-space($topicTitle)"/>
            </xsl:when>          
            <xsl:otherwise>
                <xsl:message>Title not found</xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </topicTitle>
</xsl:template>
</xsl:stylesheet>

Code: Select all

<task
    xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
    xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
    class="- topic/topic task/task "
    ditaarch:DITAArchVersion="1.2"
    domains="(topic task) (topic hi-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d) (topic pr-d) (topic sw-d) (topic ui-d) (topic task strictTaskbody-c)"
    id="GUID-B0A2B437-00A2-4A3A-863E-02F6330415BB"   
    xml:lang="en-US">
    <title id="GUID-97B53FD5-32EB-4ACD-BDE2-5FC35C5AD912" class="- topic/title ">
        <ph id="GUID-D05C0990-7BAE-4463-9A33-E4086E2489D9" 
        class="- topic/ph ">
        <ph id="d7e29" 
            ishcondition="(country=Australia) or (country=Canada) 
            or (country=Japan) or (country='United States')" 
            class="- topic/ph ">Your device named ABC</ph>
        </ph> is Out of Sync
    </title>
 </task>
and the output is

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<topicTitle>Your device named ABC is Out of Sync</topicTitle>
However, if I instead use the XPath/XQuery Builder and apply the following XPath to the same XML

Code: Select all

/*[contains(@class, ' topic/topic ')]/[contains(@class, ' topic/title ')] 
The result is

Code: Select all

is Out of Sync
Can someone explain why the output is different from both approaches to applying XSLT to XML?

Any advice appreciated,
Regards,
Ann
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Difference output when using XSLT Debugger versus XPath/XQuery Builder

Post by Radu »

Hello Ann,

Your XPath expression when run in the XPath Builder returns an XML node (the title node). And we attempt to present in the "XPath" results some of the text content from that node. In your case our attempt to serialize and present some of the text node from the title should indeed work better and present "Your device named ABC is Out of Sync". I added an internal issue to improve the way in which we compute the text that is displayed when running an XPath which returns an element, pasting the issue ID below for future reference:

EXM-52274 Improve description of xpath result when it contains multiple nodes

You could also re-write your XPath expression to return directly the joining of all text nodes:

Code: Select all

//*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]/normalize-space(string-join(.//text(), ''))
and this should work better when displayed in the XPath results.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Re: Difference output when using XSLT Debugger versus XPath/XQuery Builder

Post by ann.jensen »

Thank you Radu, your advice around the rewrite of the XPath query has resolved my problem.
Regards,
Ann
Post Reply