Hi all,
Can somebody give a good explanation on a right answer to the question below (from XMLWhiz
test)?
When I tested this, I've got 9 values in output (?!!!).
Thanks a lot,
Svetlana.
Q:
====
How many elements will be output when the following XSL sheet is applied to the following XML document?
--------------------XSL Document-------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name='Root'>
<xsl:call-template name="v3"/>
</xsl:element>
</xsl:template>
<xsl:template name="v3">
<xsl:variable name="v3List" select="//a[not(following::x=.)]|//x[not(preceding::a=.)] "/>
<xsl:for-each select="$v3List">
<a><xsl:value-of select="."/></a>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
--------------------XML Document-------------------------
<Root>
<B>
<a>1</a>
<a>2</a>
<a>1</a>
<x>3</x>
<x>4</x>
<x>2</x>
</B>
<B>
<a>3</a>
<a>1</a>
<a>2</a>
<a>3</a>
<x>5</x>
<x>4</x>
<x>1</x>
</B>
</Root>
Select from:
A) 7
B) 8
C) 3
D) 5
E) error
==========
A:
==========
A is correct. It will take 3 values from first selection "a[not(following::x=.)]" (these three coming from second "B"), and 4 values from second part "x[not(preceding::a=.)]" 2 each from both "B"). All the selected elements are marked in the XML document below:
---------------------XML Document-----------------------
<Root>
<B>
<a>1</a>
<a>2</a>
<a>1</a>
<x>3</x>(selected)
<x>4</x>(selected)
<x>2</x>
</B>
<B>
<a>3</a>(selected)
<a>1</a>
<a>2</a>(selected)
<a>3</a>(selected)
<x>5</x>(selected)
<x>4</x>(selected)
<x>1</x>
</B>
</Root>