[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] loop without switching context
I ran into a challenge today that I ended up working around. I wonder though if there is a direct solution. Is there a way to write a loop without switching context? I am using XSLT 2.0 and Saxon. If I loop through a set of values using <xsl:for-each> then my context is set to the xml that contains that data. But I want my context to be set to the xml before I entered the for-each. Some example code. I had this. <xsl:call-template name="a"><xsl:with-param name="x">01</xsl:with-param></xsl:call-templates> <xsl:call-template name="a"><xsl:with-param name="x">02</xsl:with-param></xsl:call-templates> {duplicated about 10 times} It works okay, but it is hard-coded (bad). I will have cases where my list of x values will vary, but they will always be short strings like {01,02,A1,B3}. And the number of values will always be less than 20. So I thought of using xsl:for-each on a data file for the x values. Like this <xsl:variable name="datafile">../data.xml</xsl:variable> <xsl:for-each select="document($datafile)/data/xvals/x"> <xsl:call-template name="a"><xsl:with-param name="x">01</xsl:with-param></xsl:call-templates> </xsl:for-each> The loop works, but it switches my context so that template "a" no longer has the xml it needs. I realized I could pass in the context node as a param, but it seems that is only giving me access to children and not ancestors of the context node. Maybe I have hit a case where I am just modeling the project wrong and need to rethink it some. Or, is there a way to write a loop without switching context? Thanks, Fred
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|