Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I know this isn't exactly a sharepoint question - but its the closest stack exchange site I could find to post it in.

I'm using Infopath 2007. For this specific problem, we won't have access to a Sharepoint server (where we can roll this stuff up with ease) for at least six months. Therefore, I need to roll up many XML documents (saved from Infopath) using Infopath's Merge Forms feature. This feature however seems to be quite limited in functionality and therefore I need to construct a custom merge template so that Infopath will know how to merge the documents correctly. Doing this with code isn't an option.

I`ve been following instructions on the MSDN site for how to complete this custom merge. The problem is that I have never worked with XSLT and the examples I find on the web tend to all deal with different scenarios. I'm confused over what the XSLT should look like. Hopefully with an example for my first report I can figure out the rest.

There are two schemas. One is for the force report and one is for the consolidated weather report. A force report is used on a construction site to see how many tradespeople and how many office people are present. It also records that day's weather conditions. My focus is extracting the weather elements out of the Force Report, and consolidating many Force Reports (via a merge) into one weather report.

The weather report is going to take three nodes from each ForceReport XML file and add them into a sequence. This report will essentially list each day, and what the weather was like that day. I`ve called this ForceReport_Weather.xsd

ForceReport.xsd This is the main report that is filled out each day. Each report is saved in a separate XML file, named for the date it was taken.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema targetNamespace="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-07-04T13:49:44" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-07-04T13:49:44" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="ForceReport">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="my:TemperatureHigh" minOccurs="0"/>
                        <xsd:element ref="my:TemperatureLow" minOccurs="0"/>
                        <xsd:element ref="my:ForceReportDate" minOccurs="0"/>
                        <xsd:element ref="my:WeatherConditions" minOccurs="0"/>
                        <xsd:element ref="my:NMN" minOccurs="0"/>
                        <xsd:element ref="my:MAN" minOccurs="0"/>
                    </xsd:sequence>
                    <xsd:anyAttribute processContents="lax" namespace="http://www.w3.org/XML/1998/namespace"/>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="TemperatureHigh" type="xsd:integer"/>
            <xsd:element name="TemperatureLow" type="my:requiredString"/>
            <xsd:element name="ForceReportDate" type="xsd:date"/>
            <xsd:element name="WeatherConditions" type="my:requiredString"/>
            <xsd:element name="NMN">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="my:Discipline" minOccurs="0" maxOccurs="unbounded"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="Discipline">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="my:DisciplineName" minOccurs="0"/>
                        <xsd:element ref="my:DisciplineCode" minOccurs="0"/>
                        <xsd:element ref="my:NMN_Site" minOccurs="0"/>
                        <xsd:element ref="my:NMN_Leave" minOccurs="0"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="DisciplineName" type="my:requiredString"/>
            <xsd:element name="DisciplineCode" type="my:requiredString"/>
            <xsd:element name="NMN_Site" nillable="true" type="xsd:integer"/>
            <xsd:element name="NMN_Leave" nillable="true" type="xsd:integer"/>
            <xsd:element name="MAN">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="my:Trade" minOccurs="0" maxOccurs="unbounded"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="Trade">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="my:TradeName" minOccurs="0"/>
                        <xsd:element ref="my:AP_Site" minOccurs="0"/>
                        <xsd:element ref="my:AP_Leave" minOccurs="0"/>
                        <xsd:element ref="my:JM_Site" minOccurs="0"/>
                        <xsd:element ref="my:JM_Leave" minOccurs="0"/>
                        <xsd:element ref="my:FM_Site" minOccurs="0"/>
                        <xsd:element ref="my:FM_Leave" minOccurs="0"/>
                        <xsd:element ref="my:GF_Site" minOccurs="0"/>
                        <xsd:element ref="my:GF_Leave" minOccurs="0"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="TradeName" type="my:requiredString"/>
            <xsd:element name="AP_Site" nillable="true" type="xsd:integer"/>
            <xsd:element name="AP_Leave" nillable="true" type="xsd:integer"/>
            <xsd:element name="JM_Site" nillable="true" type="xsd:integer"/>
            <xsd:element name="JM_Leave" nillable="true" type="xsd:integer"/>
            <xsd:element name="FM_Site" nillable="true" type="xsd:integer"/>
            <xsd:element name="FM_Leave" nillable="true" type="xsd:integer"/>
            <xsd:element name="GF_Site" nillable="true" type="xsd:integer"/>
            <xsd:element name="GF_Leave" nillable="true" type="xsd:integer"/>
            <xsd:simpleType name="requiredString">
                <xsd:restriction base="xsd:string">
                    <xsd:minLength value="1"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:simpleType name="requiredAnyURI">
                <xsd:restriction base="xsd:anyURI">
                    <xsd:minLength value="1"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:schema>

ForceReport_Weather.xsd This is the schema for the consolidated weather report. Each ForceReport file has a date, high temp, low temp, and weather conditions. Each file will need to be transformed into a separate node in the sequence.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema targetNamespace="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-07-04T13:49:44" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-07-04T13:49:44" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="ForceReport_Weather">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element ref="my:WeatherReport" minOccurs="0" maxOccurs="unbounded"/>
                </xsd:sequence>
                <xsd:anyAttribute processContents="lax" namespace="http://www.w3.org/XML/1998/namespace"/>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="WeatherReport">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element ref="my:TemperatureHigh" minOccurs="0"/>
                    <xsd:element ref="my:TemperatureLow" minOccurs="0"/>
                    <xsd:element ref="my:ForceReportDate" minOccurs="0"/>
                    <xsd:element ref="my:WeatherConditions" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="TemperatureHigh" type="xsd:integer"/>
        <xsd:element name="TemperatureLow" type="my:requiredString"/>
        <xsd:element name="ForceReportDate" type="xsd:date"/>
        <xsd:element name="WeatherConditions" type="my:requiredString"/>
        <xsd:simpleType name="requiredString">
            <xsd:restriction base="xsd:string">
                <xsd:minLength value="1"/>
            </xsd:restriction>
        </xsd:simpleType>
        <xsd:simpleType name="requiredAnyURI">
            <xsd:restriction base="xsd:anyURI">
                <xsd:minLength value="1"/>
            </xsd:restriction>
        </xsd:simpleType>
        <xsd:simpleType name="requiredBase64Binary">
            <xsd:restriction base="xsd:base64Binary">
                <xsd:minLength value="1"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:schema>

Here is a sample of what the result of a ForceReport_Weather merge should look like (I manually entered and saved this for demonstration):

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.43" productVersion="14.0.0" PIVersion="1.0.0.0" href="WeatherRollUp.xsn" name="urn:schemas-microsoft-com:office:infopath:WeatherRollUp:-myXSD-2011-07-04T13-49-44" ?><?mso-application progid="InfoPath.Document"?><my:ForceReport_Weather xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-07-04T13:49:44" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-ca">
    <my:WeatherReport>
        <my:TemperatureHigh>12</my:TemperatureHigh>
        <my:TemperatureLow>11</my:TemperatureLow>
        <my:ForceReportDate>2011-08-02</my:ForceReportDate>
        <my:WeatherConditions>Sunny</my:WeatherConditions>
    </my:WeatherReport>
    <my:WeatherReport>
        <my:TemperatureHigh>13</my:TemperatureHigh>
        <my:TemperatureLow>10</my:TemperatureLow>
        <my:ForceReportDate>2011-08-03</my:ForceReportDate>
        <my:WeatherConditions>Sunny</my:WeatherConditions>
    </my:WeatherReport>
</my:ForceReport_Weather>

Lastly, I want to stress that I am at a loss for even where to begin. Here is what I have written for an XSLT so far...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:agg="http://schemas.microsoft.com/office/infopath/2003/aggregation"
xmlns:target="http://schemas.microsoft.com/office/infopath/2003/aggregation-target"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-05-29T20:30:47">

  <xsl:template match="my:ForceReport">
    <my:WeatherReport>
      <my:ForceReportDate>
        <xsl:value-of select="./ForceReportDate"/>
      </my:ForceReportDate>
      <my:WeatherConditions>
        <xsl:value-of select="./WeatherConditions"/>
      </my:WeatherConditions>
      <my:TemperatureHigh>
        <xsl:value-of select="./TemperatureHigh"/>
      </my:TemperatureHigh>
      <my:TemperatureLow>
        <xsl:value-of select="./TemperatureLow"/>
      </my:TemperatureLow>
    </my:WeatherReport>
  </xsl:template>
</xsl:stylesheet>

I would imagine this to match each ForceReport node in the source file(s) .. and move those four elements over to the target file. I haveve seen For-Each used.. I have seen insert-after used .. seen the aggregation used .. maybe its simple and I am getting confused by everything that is out there. Any help would be appreciated.

The other part of the problem is that I do not even know how I am going to test a solution - since if it doesn't work infopath will simply do nothing - I won't know where to begin troubleshooting. Is there a way to test this outside infopath to ensure I have my XSLT correct?

share|improve this question
Try www.infoPathDev.com. – Muhimbi Aug 8 '11 at 6:02
Was my first stop actually .. couldn't help. – Yesurbius Aug 8 '11 at 6:09
Also try the Microsoft forums. Sorry we can't help here. – Alex Angas Sep 12 '11 at 3:26

closed as off topic by Alex Angas Sep 12 '11 at 3:26

Questions on SharePoint Stack Exchange are expected to relate to SharePoint within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.