Jump to content

[SOLVED] XPath / XSLT issue: why don't I get the text()?


Recommended Posts

Hi everyone

as I don't think I'll ever figure this out on my own (even with all the doc I read), please tell me what I do wrong, even if it is strictly speaking a xslt-problem. But as XMLSpy evaluates my XPath how I want it to, but not  the built-in XSLT-processor in 5.2.6-2ubuntu4.1...:

I've got a html-fragment like this:

<h5><b>Art. 1</b> Persoenlicher Geltungsbereich</h5>

As result of the transformation I'd like to have something as:

<articleMetadata>
<articleNumber>Art. 1</articleNumber>
<articleHeader><text>
Persoenlicher Geltungsbereich
</text></articleHeader>

I try to achieve this by using:

<xsl:template match="h5">
	<articleMetadata>
		<xsl:apply-templates select="b"/>
		<articleHeader><text>
			<xsl:value-of select="text()"/>
		</text></articleHeader>
	</articleMetadata>
</xsl:template>
<!-- Artikelnummer -->	
<xsl:template match="b">
	<articleNumber>
		<xsl:value-of select="."/>
	</articleNumber>
</xsl:template>

Unfortunately, text() only gives me an empty string. If I try out the full XPath in XMLSpy, text() points me to "Persoenlicher Geltungsbereich".

 

What don't I understand? Thanks for your help!

Daniel

Thanks for the answer and sorry for posting to the wrong forum!

 

Looks fine to me.  How do you know it's blank?

When I do a

$domart = $procart->transformToDoc($docart);
echo htmlentities($domart->saveXML());

all I get is

<articleMetadata>
  <articleNumber>Art. 1</articleNumber>
  <articleHeader><text> </text></articleHeader>
</articleMetadata>

 

Try hard-coding some text: ...

This indeed gives me "text :" in the transformed DOM

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.