Hi Juliette--
In order for your inner tests to work as you intend, you need to change the context. To do that, you can use a for-each (even though there's only one target element, for-each will change the context to that element so that the Xpath expressions inside the for-each will be interpreted relative to the target element. So you want something like this:
<xsl:when test="$targetelem">
<xsl:for-each select="$targetelem">
<xsl:choose>
<xsl:when test="parent::subpara1"><fo:inline color="green">TEST</fo:inline></xsl:when>
<xsl:when test="parent::para0"><fo:inline color="red">TEST</fo:inline></xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:when>
But I think I see the problem now, after looking back at the markup sample you sent earlier. The problem is that the target element for your xref isn't a child or descendant of the subpara1 or the para0, it *is* the subpara1 or the para0. From your earlier markup sample:
<book_chapter chap_num="1" id="F423" linkid="48" omitfromcp="1">
<title>Organisation and Responsibilities</title>
<dmodule id="A5" dm_num="0" linkid="4769" docname="DMC-VBHL-GEN-01-01-0002-0000-000A-Z_000-00.xml">
<content>
<descript>
<para0 id="JG01">
<title>Test Title 1</title>
<para>Refer to <xref xrefid="6412-JG02a" xidtype="para" target="JG02" title="Test" title=" 2"="/>.</para>
<subpara1 id="JG02">
<title>Test Title 2</title>
<para>Refer to <xref xrefid="6412-JG01a" xidtype="para" target="JG01" title="Test" title=" 1"="/>.</para>
</subpara1>
</para0>
</descript>
</content>
</dmodule>
</book_chapter>
See how the id that matches the target in the xref is the actual para0 or subpara1 itself. So that makes the Xpath even simpler: just use $targetelem directly. To test which kind of thing it is, you can use the self axis, something like this:
<xsl:template match="xref">
<xsl:variable name="targetelem" select="id(@target)"/">
<xsl:choose>
<xsl:when test="$targetelem/self::para0">
</xsl:when>
<xsl:when test="$targetelem/self::subpara1">
</xsl:when>
</xsl:choose>
</xsl:template>
Hopefully that will get you over the last hurdle.
--Clay
----------
In order for your inner tests to work as you intend, you need to change the context. To do that, you can use a for-each (even though there's only one target element, for-each will change the context to that element so that the Xpath expressions inside the for-each will be interpreted relative to the target element. So you want something like this:
<xsl:when test="$targetelem">
<xsl:for-each select="$targetelem">
<xsl:choose>
<xsl:when test="parent::subpara1"><fo:inline color="green">TEST</fo:inline></xsl:when>
<xsl:when test="parent::para0"><fo:inline color="red">TEST</fo:inline></xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:when>
But I think I see the problem now, after looking back at the markup sample you sent earlier. The problem is that the target element for your xref isn't a child or descendant of the subpara1 or the para0, it *is* the subpara1 or the para0. From your earlier markup sample:
<book_chapter chap_num="1" id="F423" linkid="48" omitfromcp="1">
<title>Organisation and Responsibilities</title>
<dmodule id="A5" dm_num="0" linkid="4769" docname="DMC-VBHL-GEN-01-01-0002-0000-000A-Z_000-00.xml">
<content>
<descript>
<para0 id="JG01">
<title>Test Title 1</title>
<para>Refer to <xref xrefid="6412-JG02a" xidtype="para" target="JG02" title="Test" title=" 2"="/>.</para>
<subpara1 id="JG02">
<title>Test Title 2</title>
<para>Refer to <xref xrefid="6412-JG01a" xidtype="para" target="JG01" title="Test" title=" 1"="/>.</para>
</subpara1>
</para0>
</descript>
</content>
</dmodule>
</book_chapter>
See how the id that matches the target in the xref is the actual para0 or subpara1 itself. So that makes the Xpath even simpler: just use $targetelem directly. To test which kind of thing it is, you can use the self axis, something like this:
<xsl:template match="xref">
<xsl:variable name="targetelem" select="id(@target)"/">
<xsl:choose>
<xsl:when test="$targetelem/self::para0">
</xsl:when>
<xsl:when test="$targetelem/self::subpara1">
</xsl:when>
</xsl:choose>
</xsl:template>
Hopefully that will get you over the last hurdle.
--Clay
----------