xsl-list
[Top] [All Lists]

[xsl] Context in nested loop

2017-07-28 09:11:23
I am unclear with the correct syntax for the corresponding context of the $name 
and $attr
variables in the following repro. For $name, mailto:../@name is what I want, 
but I know that is
incorrect and for $attr, "." gets the value and not the name. This is similar 
to a question I
had a few days ago, yet in this case I am still unable to figure it out. Does a 
way exist to avoid
the variables?

Thanks,
jlc

<root>
  <nodeA>
    <nodeB name="MyName" attrB="2" attrC="3" />
  </nodeA>
</root>

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:wix="http://schemas.microsoft.com/wix/2006/wi";
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl">
  <xsl:output encoding="UTF-8" indent="yes" method="xml" />

  <xsl:strip-space elements="*" />

  <xsl:variable name="document" select="document('file.xml')" />

  <xsl:template match="/">
    <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/foo/bar[@name=$name]/@*[local-name()=$attr]" />
          </xsl:message>
        </xsl:if>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
--~----------------------------------------------------------------
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>