(XSLT 1.0.) Given a variable called Rows, which contains the following (example):
Enter
<AllResults> <Result> <subject>can be filtered by filter 1</subject> <type>can be filtered by filter 2</type> <date>can be filtered by filter 3</date> </Result> <Result> ... </Result> </AllResults>
I have 3 filter variables. For each filter, I would like to apply a filter to the input shown above if the filter variable is not empty. I would like to save the filtered result, the elements corresponding to the filters, in a new variable. I tried the following, but I got an error message (filterResult), which is a "result tree instead of node-set". The Rows variable is node-set, as I defined with the debugger.
XSL part
<xsl:variable name="filterResult"> <xsl:choose> <xsl:when test="$filter1 != '' and $filter2 != '' and $filter3 != ''"> <xsl:copy-of select="$Rows[date=$filter1 and type=$filter2 and subject=$filter3]" /> </xsl:when> <xsl:when test="$filter1 != '' and $filter2 != ''"> <xsl:copy-of select="$Rows[date=$filter1 and type=$filter2]" /> </xsl:when> <xsl:when test="$filter1 != '' and $filter3 != ''"> <xsl:copy-of select="$Rows[date=$filter1 and subject=$filter3]" /> </xsl:when> <xsl:when test="$filter3 != '' and $filter2 != ''"> <xsl:copy-of select="$Rows[type=$filter2 and subject=$filter3]" /> </xsl:when> <xsl:when test="$filter1 != ''"> <xsl:copy-of select="$Rows[date=$filter1]" /> </xsl:when> <xsl:when test="$filter3 != ''"> <xsl:copy-of select="$Rows[subject=$filter3]" /> </xsl:when> <xsl:when test="$filter2 != ''"> <xsl:copy-of select="$Rows[type=$filter2]" /> </xsl:when> <xsl:otherwise> <xsl:copy-of select="$Rows" /> </xsl:otherwise> </xsl:choose> </xsl:variable>
I understand that copy-of creates a result tree, not node-set, but I'm not sure HOW to create a node set, given my requirements for the 3 filters that I described above.
Additional Information
I know that I could do something like <xsl:variable name="me" select="/set/node"/> , which would create a variable containing the node set, but I donβt see how this helps me since I have many possible conditions (given the three filters).
Kylem
source share