xsl-list
[Top] [All Lists]

Re: [xsl] Context in nested loop

2017-07-28 09:48:27
On 28.07.2017 16:30, Joseph L. Casale jcasale(_at_)activenetwerx(_dot_)com 
wrote:

Its schema is exactly the same as the sample XML, it’s a similar document

with different values. To be honest, I whipped this repro up in vim so in 
reality

the xpath selection within the message should correspond to the same element

path I am iterating over but in the alternate document. In that case it should 
be



     <xsl:value-of 
select="$document/root/nodeA/nodeB[@name=$name]/@*[local-name()=$attr]" />


So you have

    <xsl:for-each select="/root/nodeA/nodeB">
      <xsl:variable name="name" select="@name"/>
      <xsl:for-each select="@*">
        <xsl:variable name="attr" select="local-name()"/>
        <xsl:if test="name()!='name'">
          <xsl:message>
<xsl:value-of select="$document/root/nodeA/nodeB[@name=$name]/@*[local-name()=$attr]" />
          </xsl:message>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>

and of course the inner variable can be avoided with

    <xsl:for-each select="/root/nodeA/nodeB">
      <xsl:variable name="name" select="@name"/>
      <xsl:for-each select="@*">
        <xsl:if test="name()!='name'">
          <xsl:message>
<xsl:value-of select="$document/root/nodeA/nodeB[@name=$name]/@*[local-name()=local-name(current())]" />
          </xsl:message>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>

and the outer with

    <xsl:for-each select="/root/nodeA/nodeB">
      <xsl:for-each select="@*">
        <xsl:if test="name()!='name'">
          <xsl:message>
<xsl:value-of select="$document/root/nodeA/nodeB[@name=current()/../@name]/@*[local-name()=local-name(current())]" />
          </xsl:message>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>

if I am not mistaken.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>