0
votes

So the bigger picture is that I'm trying to determine why there's "content in prolog" (which is not allowed).

It looks like the content that's being included is coming from the result of this XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wd="urn:com.workday/bsvc">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*" />

    <!-- <xsl:template match="props['xpath_matchHoursDateType']">  -->
    <xsl:template match="wd:Report_Data/wd:Report_Entry[1]/wd:Employee_ID">
        <Root>
            <xsl:copy-of select="."/>
        </Root>
    </xsl:template>
</xsl:stylesheet>

...which, when applied to the following XML, produces a result that I find surprising:

<wd:Report_Data xmlns:wd="urn:com.workday/bsvc">
    <wd:Report_Entry>
        <wd:Employee_ID>123456</wd:Employee_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>234567</wd:Employee_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>345678</wd:Employee_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>456789</wd:Employee_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:RBO_Group>
            <wd:Date_Worked>12/15/2014</wd:Date_Worked>
            <wd:Hours>41.53</wd:Hours>
            <wd:Type>TypeA</wd:Type>
            <wd:Process_Date>09/20/2019</wd:Process_Date>
        </wd:RBO_Group>
        <wd:RBO_Group>
            <wd:Date_Worked>12/15/2014</wd:Date_Worked>
            <wd:Hours>41.53</wd:Hours>
            <wd:Type>TypeA</wd:Type>
            <wd:Process_Date>01/30/2020</wd:Process_Date>
        </wd:RBO_Group>
        <wd:Employee_ID>567890</wd:Employee_ID>
    </wd:Report_Entry>
</wd:Report_Data>

The result being:

<Root xmlns:wd="urn:com.workday/bsvc"><wd:Employee_ID>123456</wd:Employee_ID></Root>23456734567845678912/15/201441.53TypeA09/20/201912/15/201441.53TypeA01/30/2020567890

My expectation is that the template would match the "wd:Employee_ID" node of the first "wd:Report_Entry" node it finds, copy it, and then be done. So I'm surprised to see anything after the closing Root tag. I'm not the best XSL programmer, and I'm just now working with streamable XSL 3.0, so that might be part of the equation.

I'm passing this XML result along to another XSL transform, which SEEMS to be complaining about content being included in the prolog, which I can only imagine is this extra content after the root closes.

So, why is the rest of the XML content being added to the result after the template is (AFAIK) complete?

1

1 Answers

1
votes

Every XSLT stylesheet contains what's called "default rules". These will recursively process the input document in the following fashion, starting from the root node:

  1. find child nodes, apply templates to them
  2. if a child node is a text node, copy the text to the output
  3. if a child node is an element node, start at 1.
  4. any other node will be skipped

Your stylesheet only contains a single template matching a single type of node, overriding the default behavior for this type of node.

It contains nothing that would prevent the default rules from running, so you get all kinds of text nodes as part of the output.

Change your stylesheet like this:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wd="urn:com.workday/bsvc">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*" />

    <xsl:template match="/">
        <xsl:apply-templates select="wd:Report_Data/wd:Report_Entry[1]/wd:Employee_ID" />
    </xsl:template>

    <!-- <xsl:template match="props['xpath_matchHoursDateType']">  -->
    <xsl:template match="wd:Report_Data/wd:Report_Entry[1]/wd:Employee_ID">
        <Root>
            <xsl:copy-of select="."/>
        </Root>
    </xsl:template>
</xsl:stylesheet>

and it will start to work the way you expect.

The template match="/" will override default behavior directly at the root node and leave no room for the default rules to kick in.