Trying to write an XSLT 1.0 template that will create elements from the Filemaker FMPXMLRESULT METADATA/@NAME attribute. Here's sample XML:
<?xml version="1.0" encoding="UTF-16" ?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Type" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Level" TYPE="TEXT"/>
</METADATA>
<RESULTSET FOUND="2">
<ROW MODID="18" RECORDID="28133">
<COL><DATA>O1</DATA></COL>
<COL><DATA>L1</DATA></COL>
</ROW>
<ROW MODID="5" RECORDID="28153">
<COL><DATA>D12</DATA></COL>
<COL><DATA>L1</DATA></COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>
And here's my XLST progress so far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fmp">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:variable name="labels" select="fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD/@NAME"/>
<xsl:template match="fmp:FMPXMLRESULT">
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<PLAN>
<xsl:for-each select="fmp:RESULTSET/fmp:ROW">
<Sign>
<xsl:for-each select="fmp:COL">
<xsl:element name="{$labels[position()]}">
<xsl:value-of select="fmp:DATA"/>
</xsl:element>
</xsl:for-each>
</Sign>
</xsl:for-each>
</PLAN>
</FMPXMLRESULT>
</xsl:template>
</xsl:stylesheet>
开发者_如何学Python
My trouble is in line 13:
<xsl:element name="{$labels[position()]}">
Where position() doesn't relate to the position of fmp:COL, and likely is meaningless the way I've used it.
What I'd like to reference is the current fmp:COL element in the xsl:for-each loop, but I suspect that this can't be obtained in XLST 1.0 given the way I'm approaching it.
Does anyone have suggestions or pointers on how to proceed?
Many thanks!
Charles
Take a look at this question/answer. It might be what you are looking for. Filemaker XSL Select Column By Name
Update: This post also has great solutions to a similar question: XSLT question. How to pair field tags with data when original XML has them in separate sections?
精彩评论