I'm trying to build an xml file from data in a Filemaker database. I can get the basic structure of the XML to work but am having issues rendering portal rows in the right way.
Here is the end result of what I'm trying to achieve.
<product>
<model>Model</model>
<caliber>Caliber</caliber>
<submodel>Sub Model</submodel>
<Dimensions>
<label>Overall length</label>
<label>Overall height</label>
<value>178 mm</value>
<value>138 mm</value>
</Dimensions>
<weight>
<label>Overall weight</label>
<label>with magazine</label>
<value>739 g</value>
<value>91 g</value>
</weight>
</product>
The Model and Caliber and Submodel items are fields in a table in my database. The dimensions and weight are pulling from a related table as a portal. The relationship key is the model.
Each portal row as a Category, Label and Value.
I'm trying to write an if statement in the XSL file that will grab all the portal rows with a category of "Dimensions" and group them together. The same for Weight.
Here is my current working XSL file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0" exclude-result-prefixes="fmp">
<xsl:output method="xml" version="1.0" encoding="windows-1251" indent="yes"/>
<xsl:template match="/">
<product>
<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
<model>
<xsl:value-of select="fmp:COL[2]/fmp:DATA"/>
</model>
<caliber>
<xsl:value-of select="fmp:COL[1]/fmp:DATA"/>
</caliber>
<submodel>
<xsl:value-of select="fmp:COL[4]/fmp:DATA"/>
</submodel>
<specs>
<xsl:for-each select="fmp:COL[10]/fmp:DATA">
<category>
<xsl:value-of select="."/>
</category>
</xsl:for-each>
<xsl:for-each select="fmp:COL[8]/fmp:DATA">
<label>
<xsl:value-of select="."/>
</label>
</xsl:for-each>
<xsl:for-each select="fmp:COL[9]/fmp:DATA">
<value>
<xsl:value-of select="."/>
</value>
</xsl:for-each>
</specs>
</xsl:for-each>
</product>
</xsl:template>
</xsl:stylesheet>
This will output all the information I need but puts all the categories from the portal row together. I'm very new to XSL and don't know how to formulate the if statement.
I need to change the info inside to the if statement.
Here's what I was playing with:
<xsl:if test="fmp:COL[10]/fmp:DATA= 'Dimensions'">
<Dimensions>
<label>Overall length</label>
<label>Overall height</label>
<value>178 mm</value>
<value>138 mm</value>
</Dimensions>
</xsl:if>
Here is the raw export from Filemaker.
<?xml version="1.0" encoding="UTF-8"?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="03-15-2012" NAME="FileMaker" VERSION="ProAdvanced 12.0v1" />
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="HK Product Database.fmp12" RECORDS="61" TIMEFORMAT="h:mm:ss a" />
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Caliber" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Model" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ModelID" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="PrimaryCategory" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ProductID" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SubModel" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Models::WP Post ID" TYPE="NUMBER" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Specs::SpecLabel" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Specs::SpecData" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Specs::SpecCategory" TYPE="TEXT" />
</METADATA>
<RESULTSET FOUND="61">
<ROW MODID="1" RECORDID="196">
<COL>
<DATA>9 mm x 19</DATA>
</COL>
<COL>
<DATA>P59</DATA>
</COL>
<COL>
<DATA>P59</DATA>
</COL>
<COL>
<DATA>Semi-Automatic Pistols</DATA>
</COL>
<COL>
<DATA>P30-9</DATA>
</COL>
<COL>
<DATA>P30</DATA>
</COL>
<COL>
<DATA>181</DATA>
</COL>
<COL>
<DATA>Overall length</DATA>
<DATA>Overall height</DATA>
<DATA>Overall width w/lever</DATA>
<DATA>Barrel length</DATA>
<DATA>Sight radius</DATA>
<DATA>With magazine</DATA>
<DATA>Magazine</DATA>
<DATA>Magazine capacity</DATA>
<DATA>Trigger system</DATA>
<DATA>Trigger pull (N)</DATA>
<DATA>Trigger travel</DATA>
<DATA>Sights</DATA>
</COL>
<COL>
<DATA>178 mm</DATA>
<DATA>138 mm</DATA>
<DATA>35 mm</DATA>
<DATA>98 mm</DATA>
<DATA>149 mm</DATA>
<DATA>739 g</DATA>
<DATA>91 g</DATA>
<DATA>15 Cartridges</DATA>
<DATA>SA/DA</DATA>
<DATA>* 20 + 4/-2 (SA)
51 +/- 5 (DA)</DATA>
<DATA>.25 inch (SA)
< .55 inch (DA)</DATA>
<DATA>Fixed (Open square notch rear sight with contrast points)</DATA>
</COL>
<COL>
<DATA>Dimensions</DATA>
<DATA>Dimensions</DATA>
<DATA>Dimensions</DATA>
<DATA>Dimensions</DATA>
<DATA>Dimensions</DATA>
<DATA>Weight</DATA>
<DATA>Weight</DATA>
<DATA>Other Specifications</DATA>
<DATA>Other Specifications</DATA>
<DATA>Other Specifications</DATA>
<DATA>Other Specifications</DATA>
<DATA>Other Specifications</DATA>
</COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>
It's not working right. Any help would be appreciated!
Edit:
Here is an update of where I"m at:
This stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0" exclude-result-prefixes="fmp">
<xsl:output method="xml" version="1.0" encoding="windows-1251" indent="yes"/>
<xsl:template match="/">
<product>
<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
<model>
<xsl:value-of select="fmp:COL[2]/fmp:DATA"/>
</model>
<productID>
<xsl:value-of select="fmp:COL[5]/fmp:DATA"/>
</productID>
<caliber>
<xsl:value-of select="fmp:COL[1]/fmp:DATA"/>
</caliber>
<submodel>
<xsl:value-of select="fmp:COL[4]/fmp:DATA"/>
</submodel>
<xsl:if test="fmp:COL[10]/fmp:DATA= 'Dimensions'">
<Dimensions>
<xsl:value-of select="."/>
</Dimensions>
</xsl:if>
<specs>
<xsl:for-each select="fmp:COL[10]/fmp:DATA">
<category>
<xsl:value-of select="."/>
</category>
</xsl:for-each>
<xsl:for-each select="fmp:COL[8]/fmp:DATA">
<label>
<xsl:value-of select="."/>
</label>
</xsl:for-each>
<xsl:for-each select="fmp:COL[9]/fmp:DATA">
<value>
<xsl:value-of select="."/>
</value>
</xsl:for-each>
</specs>
</xsl:for-each>
</product>
</xsl:template>
</xsl:stylesheet>
Renders this XML:
<product>
<model>P30</model>
<productID>P30-9</productID>
<caliber>9 mm x 19</caliber>
<submodel>Semi-Automatic Pistols</submodel>
<Dimensions>9 mm x 19P30P30Semi-Automatic PistolsP30-9P30181Overall lengthOverall heightOverall width w/leverBarrel lengthSight radiusWith magazineMagazineMagazine capacityTrigger systemTrigger pull (N)Trigger travelSights178 mm138 mm35 mm98 mm149 mm739 g91 g15 CartridgesSA/DA* 20 + 4/-2 (SA)
51 +/- 5 (DA).25 inch (SA)
< .55 inch (DA)Fixed (Open square notch rear sight with contrast points)
DimensionsDimensionsDimensionsDimensionsDimensionsWeightWeightOther SpecificationsOther SpecificationsOther SpecificationsOther SpecificationsOther Specifications</Dimensions>
<specs>
<category>Dimensions</category>
<category>Dimensions</category>
<category>Dimensions</category>
<category>Dimensions</category>
<category>Dimensions</category>
<category>Weight</category>
<category>Weight</category>
<category>Other Specifications</category>
<category>Other Specifications</category>
<category>Other Specifications</category>
<category>Other Specifications</category>
<category>Other Specifications</category>
<label>Overall length</label>
<label>Overall height</label>
<label>Overall width w/lever</label>
<label>Barrel length</label>
<label>Sight radius</label>
<label>With magazine</label>
<label>Magazine</label>
<label>Magazine capacity</label>
<label>Trigger system</label>
<label>Trigger pull (N)</label>
<label>Trigger travel</label>
<label>Sights</label>
<value>178 mm</value>
<value>138 mm</value>
<value>35 mm</value>
<value>98 mm</value>
<value>149 mm</value>
<value>739 g</value>
<value>91 g</value>
<value>15 Cartridges</value>
<value>SA/DA</value>
<value>* 20 + 4/-2 (SA)
51 +/- 5 (DA)</value>
<value>.25 inch (SA)
< .55 inch (DA)</value>
<value>Fixed (Open square notch rear sight with contrast points)
</value>
</specs>
</product>
Using the same source XML. The dimensions if statement is working but now just need to separate that content.