title: build node set dynamically based on input xml with xslt1.0
body: <p>When using the xslt document() function. Reading for example following xml:</p>
  
  <pre><code>&lt;Products&gt;
      &lt;Product productCode="SQUARE-BLUE-EXTRA-A-10-MAY" messageType="FOUNTAIN" messageTag="F"/&gt;
      &lt;Product productCode="SQUARE-RED-EXTRA-B-20-JUNE" messageType="FOUNTAIN" messageTag="F"/&gt;
  &lt;/Products&gt;
  </code></pre>
  
  <p>The output is a node-set which can be stored in a variable.
  Instead of reading a xml document i want to build this variable with a nodeset dynamically based upon a xml input.</p>
  
  <p>example of a xml input:</p>
  
  <pre><code>&lt;Root&gt;
      &lt;Object&gt;
          &lt;QuoteLineItems&gt;
              &lt;Object&gt;
                  &lt;Product2Id&gt;
                      &lt;ProductCode&gt;SQUARE&lt;/ProductCode&gt;
                  &lt;/Product2Id&gt;
                  &lt;QuoteLineItems&gt;
                      &lt;Object&gt;
                          &lt;Product2Id&gt;
                              &lt;ProductCode&gt;BLUE&lt;/ProductCode&gt;
                          &lt;/Product2Id&gt;
                          &lt;QuoteLineItems&gt;
                              &lt;Object&gt;
                                  &lt;ServiceDate&gt;MAY&lt;/ServiceDate&gt;
                                  &lt;attributes&gt;
                                      &lt;Object&gt;
                                          &lt;attributeuniquecode&gt;ATTR_VOLUMEPERCENTAGE&lt;/attributeuniquecode&gt;
                                          &lt;attributedisplayname&gt;Volume percentage&lt;/attributedisplayname&gt;
                                          &lt;value&gt;10&lt;/value&gt;
                                      &lt;/Object&gt;
                                      &lt;Object&gt;
                                          &lt;attributeuniquecode&gt;ATTR_TYPE&lt;/attributeuniquecode&gt;
                                          &lt;attributedisplayname&gt;Type&lt;/attributedisplayname&gt;
                                          &lt;value&gt;A&lt;/value&gt;
                                      &lt;/Object&gt;
                                  &lt;/attributes&gt;
                                  &lt;Product2Id&gt;
                                      &lt;ProductCode&gt;EXTRA&lt;/ProductCode&gt;
                                  &lt;/Product2Id&gt;
                                  &lt;QuoteLineItems/&gt;
                              &lt;/Object&gt;
                          &lt;/QuoteLineItems&gt;
                      &lt;/Object&gt;
                      &lt;Object&gt;
                          &lt;Product2Id&gt;
                              &lt;ProductCode&gt;RED&lt;/ProductCode&gt;
                          &lt;/Product2Id&gt;
                          &lt;QuoteLineItems&gt;
                              &lt;Object&gt;
                                  &lt;ServiceDate&gt;JUNE&lt;/ServiceDate&gt;
                                  &lt;attributes&gt;
                                      &lt;Object&gt;
                                          &lt;attributeuniquecode&gt;ATTR_VOLUMEPERCENTAGE&lt;/attributeuniquecode&gt;
                                          &lt;attributedisplayname&gt;Volume percentage&lt;/attributedisplayname&gt;
                                          &lt;value&gt;20&lt;/value&gt;
                                      &lt;/Object&gt;
                                      &lt;Object&gt;
                                          &lt;attributeuniquecode&gt;ATTR_TYPE&lt;/attributeuniquecode&gt;
                                          &lt;attributedisplayname&gt;Type&lt;/attributedisplayname&gt;
                                          &lt;value&gt;B&lt;/value&gt;
                                      &lt;/Object&gt;
                                  &lt;/attributes&gt;
                                  &lt;Product2Id&gt;
                                      &lt;ProductCode&gt;EXTRA&lt;/ProductCode&gt;
                                  &lt;/Product2Id&gt;
                                  &lt;QuoteLineItems/&gt;
                              &lt;/Object&gt;
                          &lt;/QuoteLineItems&gt;
                      &lt;/Object&gt;
                  &lt;/QuoteLineItems&gt;
              &lt;/Object&gt;
          &lt;/QuoteLineItems&gt;
      &lt;/Object&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>i want to do this because i have to check a certain input xml against a lookup list(first xml).
  with further extension the lookup list with possible combinations would be endless. therefore i want to build the exact same lookup list based upon the input xml and put it in a variable with the same format as i would use the document() function.</p>
  
  <p>i've been trying things on and off for the past hours but i can't find something decent. is this possible?</p>
  
  <p>This is my current use of the document function:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
      &lt;xsl:variable name="products" select="document(file.xml)/Products/Product[@messageType=$messageType]/@productCode"/&gt;
      &lt;Messages&gt;
          &lt;xsl:for-each select="$products"&gt;
              &lt;xsl:apply-templates mode="initial" select="$root"&gt;
                  &lt;xsl:with-param name="productCode" select="."/&gt;
              &lt;/xsl:apply-templates&gt;
          &lt;/xsl:for-each&gt;
      &lt;/Messages&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>as you can see i have a variable $products. that contains my whole lookup list. i can then apply a template for each product.
  the second document is just my input xml. and i want to build a lookup list into a variable based on this input xml.</p>