user1742637
user1742637

Reputation: 11

select all text out of nodes

I have the following xml and I need to extract the text that is outside the node "justified".

<html><head><title>test</title></head><body><p><justificado><negrita>TEST.- </negrita>Hello people <negrita>it is</negrita><negrita>,</negrita> fa test ./justificado></p></body></html>

I have tried without success the following

<xsl:template match="not (*/negrita[preceding-sibling::*[1]self::negrita]])">test-123</xsl:template>

Upvotes: 1

Views: 432

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116982

I need to extract the text that is outside the node "justified".

The default behavior of an XSLT stylesheet is to copy all text nodes - so in order to extract all text that is outside a specific element, you only need an empty template matching the text nodes that are inside the specified element:

XSLT 1.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="text()[ancestor::justificado]"/>

</xsl:stylesheet>

Applied to your example input (after correcting the closing </justificado> tag!), the result is:

test

Upvotes: 1

Related Questions