1

I really can't understand this. When running my stylesheet below why are my parameters (see parameters in XML below) printed? That's the only thing that is getting printed. I expect nothing to be printed. The output is

trueSelskapet1000548

Stylesheet:

<xsl:template match="/">
    <xsl:apply-templates/>      
</xsl:template>

<xsl:template match="verticaldata/menuitems/menuitem">

</xsl:template>

Source XML (only the beginning, its valid):

<verticaldata>
    <context languagecode="en">
        <querystring/>
    </context>
    <menuitems istop="yes">
        <menuitem key="548" menukey="0" modifier="CF9FEC4718E41289CF71F83EC7C8983AA9C76E10" order="57" owner="5C2894E9CAD0B5B7B9DACE714D67651570BD1DD6" timestamp="2013-05-02 16:36" type="content" visible="yes">
            <name>NAME</name>
            <subtitle>NAME</subtitle>
            <description/>
            <keywords/>
            <parameters>
                <parameter name="pageRelationType" override="false">Selskapet</parameter>
                <parameter name="subMenuItem" override="false">true</parameter>
                <parameter name="centreColumnHeight" override="false">1000</parameter>
            </parameters>
            <data cachedisabled="true"/>

I have no clue.

Edit:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#160;">
    ]>
<xsl:stylesheet
    version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:portal="http://www.enonic.com/cms/xslt/portal"
    exclude-result-prefixes="#all">

    <xsl:output indent="no" method="html" omit-xml-declaration="yes"/>    
    <xsl:output indent="no" method="html" omit-xml-declaration="yes"/>
Borodin
  • 126,100
  • 9
  • 70
  • 144
pethel
  • 5,397
  • 12
  • 55
  • 86
  • I found the answer http://stackoverflow.com/questions/5083511/xslt-1-0-text-nodes-printing-by-default – pethel May 06 '13 at 14:49

1 Answers1

2

Quick note: going forward, please create questions where contributors can easily copy/paste your provided XML, XSLT, etc (i.e., make sure that it is well-formed). Failure to do so creates unnecessary frustration that can lead to your questions being ignored.

With that said:

The result you are seeing is 100% expected and is attributed to a built-in template rule (emphasis mine):

When a node is selected by xsl:apply-templates and there is no template rule in the stylesheet that can be used to process that node, a built-in template rule is evaluated instead. The built-in template rule for document nodes and elements nodes causes the children of the node to be processed; the built in rule for text nodes and attribute nodes causes the text to be copied to the result tree.

And, later on:

The built-in template rule for text and attribute nodes returns a text node containing the string value of the context node, unless the string value is zero-length, in which case it returns an empty sequence. It is effectively:

<xsl:template match="text()|@*" mode="#all">
  <xsl:value-of select="."/>
</xsl:template>

So, because you have not defined a template that directly addresses those text nodes, the built-in template for text nodes is implicitly called; thus, you get the string value of that text.

ABach
  • 3,743
  • 5
  • 25
  • 33
  • Thats not the complete xml. I mean the original is valid. Thanks – pethel May 06 '13 at 15:15
  • 1
    @user874774: I think you both meant "well-formed" rather than "valid" (http://stackoverflow.com/questions/134494/is-there-a-difference-between-valid-xml-and-well-formed-xml). This XML has no DTD associated with it. – LarsH May 06 '13 at 19:10