XSLT_FRESHER
XSLT_FRESHER

Reputation: 15

how to get another element of same parent in xslt?

<name><last-name>aaa</last-name><first-name>bbb</first-name></name>

template is:

<xsl:template match="last-name">
  display first-name
</xsl:template>

How to do this?

Upvotes: 0

Views: 134

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

Use:

<xsl:value-of select="../first-name"/>

Upvotes: 2

Sean B. Durkin
Sean B. Durkin

Reputation: 12729

For this input...

<name>
  <last-name>aaa</last-name>
  <first-name>bbb</first-name>
</name>

this stylesheet ...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

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

<xsl:template match="first-name" />

<xsl:template match="last-name">
  <xsl:comment>for last-name of <xsl:value-of select="." /></xsl:comment>
  <first-name>
   <xsl:value-of select="following-sibling::*" />      
  </first-name>
</xsl:template>

</xsl:stylesheet>

... produces ...

<?xml version="1.0" encoding="utf-8"?>
<!--for last-name of aaa--><first-name>bbb</first-name>

Upvotes: 1

Related Questions