tshad 0 Newbie Poster

I need to find a way to carry a value I get from a template to another template. Both templates are on the same level. I thought I could use variable or param to do this but I cannot make it work. I tried finding a way using Google but nothing has helped. It seems so simple.

If I have the following xml:

<RESPONSE MISMOVersionID="2.6">
  <REPORT _ID="Major" MajorFormType="Form102">
    <FORM _ID="Minor" MinorFormType="Form240">
      <IMAGE _ID="Im2"/>
    </FORM>
  </REPORT>
  <METHODS Description="THIS IS SUMMARY">
    <COMPARISON ID="241" ComparisonAmount="352,000">
      <SALE SequenceId="0">
        <LOCATION Address="9107 Forest Ct" Address2="Franklin, CT"/>
        <ADJUSTMENT Type="Concessions" _Description="N/A"/>
      </SALE>
    </COMPARISON>
  </METHODS>
</RESPONSE>

I need to get the MajorFormType which in this case is "Form102" and use it in my next templates. Using the following template should show what I am trying to do:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="mainForm" select="Testing"/>

  <xsl:template match="/*">
    <xsl:copy>
      <xsl:apply-templates select ="REPORT"/>
      <xsl:apply-templates select="METHODS/COMPARISON/SALE"/>
    </xsl:copy>
  </xsl:template>

  <!-- Now we handle the other sections after the DATA section -->

  <xsl:template match="REPORT">
    <xsl:variable name="mainForm" select="@MajorFormType"/>
  </xsl:template>

  <xsl:template match="SALE/*">
    <xsl:choose>
      <xsl:when test="name() = 'ADJUSTMENT'">
        <form>
          <section>
            <xsl:value-of select="../@SequenceId"/>
          </section>
          <formName>
            <xsl:value-of select="$mainForm"/>
          </formName>
          <tagName>
            <xsl:value-of select="@Type"/>
          </tagName>
          <value>
            <xsl:value-of select="@Description"/>
          </value>
        </form>
      </xsl:when>
      <xsl:when test="name() = 'LOCATION'">
        <xsl:if test="@Address">
          <form>
            <section>
              <xsl:value-of select="../@SequenceId"/>
            </section>
            <formName>
              <xsl:value-of select="$mainForm"/>
            </formName>
            <tagName>
              <xsl:text>Address</xsl:text>
            </tagName>
            <value>
              <xsl:value-of select="@Address"/>
            </value>
          </form>
        </xsl:if>
        <xsl:if test="@Address2">
          <form>
            <sectionNumber>
              <xsl:value-of select="../@SequenceId"/>
            </sectionNumber>
            <formName>
              <xsl:value-of select="$mainForm"/>
            </formName>
            <tagName>
              <xsl:text>Address2</xsl:text>
            </tagName>
            <value>
              <xsl:value-of select="@Address2"/>
            </value>
          </form>
        </xsl:if>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

$mainForm is set in REPORT and then when leaving REPORT gone.

The results I get are:

<?xml version="1.0" encoding="utf-8"?>
<RESPONSE>
  <form>
    <section>0</section>
    <formName></formName>
    <tagName>Address</tagName>
    <value>9107 Forest Ct</value>
  </form>
  <form>
    <sectionNumber>0</sectionNumber>
    <formName></formName>
    <tagName>Address2</tagName>
    <value>Franklin, CT</value>
  </form>
  <form>
    <section>0</section>
    <formName></formName>
    <tagName>Concessions</tagName>
    <value></value>
  </form>
</RESPONSE>

As you can see mainForm didn't work - <formName><formName> should be <formName>Form102<formName>.

Is there a way to accomplish this?

Thanks,

Tom

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.