librarion
librarion

Reputation: 147

XSL Select value of both attribute AND element

I'm working on an XSL stylesheet for some XML encoded finding aids. At the detailed description level for the contents of the collection, I have some containers like so:

<container type="folder">1</container>

I need to select both the @type AND the number value in the container, however all I can manage to pull is the number. How should I structure my query to get folder 1?

Upvotes: 1

Views: 1074

Answers (1)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56202

If current node is container:

<xsl:value-of select="concat(@type, ' ', text())"/>

Input XML:

<container type="folder">1</container>

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="container">
        <xsl:value-of select="concat(@type, ' ', text())"/>
    </xsl:template>
</xsl:stylesheet>

Output:

folder 1

Upvotes: 1

Related Questions