Mark Pieszak - Trilon.io
Mark Pieszak - Trilon.io

Reputation: 67171

XSL Getting node text without getting child nodes

<description>Valid Status Code required (“A”, “R”, “P”, “AR”)
    <br />
    <list type="bullet">
        <item>
            <description>A = Approved</description>
        </item>
        <item>
            <description>R = Rejected</description>
        </item>
        <item>
            <description>P = Partial</description>
        </item>
        <item>
            <description>AR = Archived</description>
        </item>
    </list>
</description>

I'm trying to get simply: Valid Status Code required (“A”, “R”, “P”, “AR”) from the description XML node, not the child nodes.

<xsl:value-of select="description" />

Doing this returns the text from everything.

How can I ignore the child nodes?

<xsl:value-of select="description(ignore children)" /> // <- pseudo-code

Upvotes: 0

Views: 46

Answers (2)

ThW
ThW

Reputation: 19512

Keep in mind that ANYTHING in a XML DOM is a node, not only the element nodes. The string is in a text node. The location path for child nodes of description that are text nodes is:

description/text()

Any element node would be:

description/*

And any node:

description/node()

Upvotes: 1

michael.hor257k
michael.hor257k

Reputation: 117140

Try:

<xsl:value-of select="description/text()"/>

Or, perhaps preferably:

<xsl:value-of select="normalize-space(description/text())"/>

Upvotes: 1

Related Questions