Vote count:
0
I have some pretty gnarly XML that was exported from Filemaker. There is a great post that almost answers my question (XSLT question. How to pair field tags with data when original XML has them in separate sections?). The xslt stylesheet from that post elegantly renames the ugly original xml with the names keyed in the <meta>
field.
That's great, except if you look below you will see that each row has multiple elements that should be named batchID
, batchPartnerID
and batchPartnerName
. However, only the first child of these three elements is renamed - the rest are simply dropped.
I imagine the stylesheet just isn't looping through the elements (the xml it was originally working on only had one child per <COL>
. Unfortunately, I'm not familiar enough with XSLT to fix this... Little help? Thanks.
Original XML:
<?xml version="1.0" encoding="UTF-8"?>
<FMPXMLRESULT xmlns="http://ift.tt/1ckTOKc">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="11-13-2014" NAME="FileMaker" VERSION="Pro 13.0v4"/>
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="ArticleIndex.fmp12" RECORDS="3678" TIMEFORMAT="h:mm:ss a"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="id" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="author" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="url" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="brand" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="publishDate" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="categoryAll" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="originalTitle" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="originalBody" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardTitle" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardSubtitle" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardPublishDate" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardBody" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardNotes" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardLastUpdated" TYPE="DATE"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="standardLastReviewed" TYPE="DATE"/>
<FIELD EMPTYOK="NO" MAXREPEAT="1" NAME="batchID" TYPE="NUMBER"/>
<FIELD EMPTYOK="NO" MAXREPEAT="1" NAME="batchPartnerID" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="batchPartnerName" TYPE="TEXT"/>
</METADATA>
<RESULTSET FOUND="12">
<ROW MODID="24" RECORDID="2028">
<COL>
<DATA>11023</DATA>
</COL>
<COL>
<DATA>Tom Myer</DATA>
</COL>
<COL>
<DATA>http://ift.tt/1FaNth1;
</COL>
<COL>
<DATA>SitePoint</DATA>
</COL>
<COL>
<DATA>August 2005</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>A Really Good Introduction to XML</DATA>
</COL>
<COL>
<DATA>A Really Good Introduction to XML —E. Berliet, Lyon, France
In this chapter, we’ll cover the basics of XML – essentially, most of the information you’ll need to know to get a handle on this exciting technology. After we’re done exploring some terminology and examples, we’ll jump right in and start working with XML documents. Then, we’ll spend some time starting the project we’ll develop through the course of this book: building an XML-powered content management system.
This excerpt is taken from No Nonsense XML Web Development with PHP, SitePoint’s new release, by Thomas Myer, which was designed to help you start using XML to build intelligent ‘Future-Proof’ PHP applications today.</DATA>
</COL>
<COL>
<DATA>A Really, Really, Really Good Introduction to XML</DATA>
</COL>
<COL>
<DATA>Starting out right</DATA>
</COL>
<COL>
<DATA>8/24/2005</DATA>
</COL>
<COL>
<DATA>A Really, Really, Really Good Introduction to XML —E. Berliet, Lyon, France
In this chapter, we’ll cover the basics of XML – essentially, most of the information you’ll need to know to get a handle on this exciting technology. After we’re done exploring some terminology and examples, we’ll jump right in and start working with XML documents. Then, we’ll spend some time starting the project we’ll develop through the course of this book: building an XML-powered content management system.
This excerpt is taken from No Nonsense XML Web Development with PHP, SitePoint’s new release, by Thomas Myer, which was designed to help you start using XML to build intelligent ‘Future-Proof’ PHP applications today.
The title contains over 350 pages of XML and PHP goodies. It walks you through the process of building a fully-functional XML-based content management system with PHP. And all the code used in the book is available to customers in a downloadalbe archive.
To find out more about “No Nonsense XML Web Development with PHP”, visit the book’s information page, or review the contents of the entire publication. As always, you can download this excerpt as a PDF if you prefer.
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>4127</DATA>
<DATA>4130</DATA>
<DATA>4136</DATA>
</COL>
<COL>
<DATA>1101</DATA>
<DATA>1107</DATA>
<DATA>1140</DATA>
</COL>
<COL>
<DATA>First Client Name</DATA>
<DATA>Second Client Name</DATA>
<DATA>Third Client Name</DATA>
</COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>
XSLT Stylesheet:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:fmp="http://ift.tt/1ckTOKc"
exclude-result-prefixes="fmp"
>
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<!-- the key indexes the METADATA fields by their position -->
<xsl:key
name="kMetaData"
match="fmp:METADATA/fmp:FIELD"
use="count(preceding-sibling::fmp:FIELD) + 1"
/>
<!-- separate templates increase readability -->
<xsl:template match="/fmp:FMPXMLRESULT">
<content>
<xsl:apply-templates select="fmp:RESULTSET/fmp:ROW" />
</content>
</xsl:template>
<xsl:template match="fmp:ROW">
<contentitem>
<xsl:apply-templates select="fmp:COL" />
</contentitem>
</xsl:template>
<xsl:template match="fmp:COL">
<!-- column name lookup is high-speed because of the key -->
<xsl:element name="{string(key('kMetaData', position())/@NAME)}">
<xsl:value-of select="fmp:DATA" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Translated XML:
<?xml version="1.0" encoding="UTF-8"?>
<content>
<contentitem>
<id>11023</id>
<author>Tom Myer</author>
<url>http://ift.tt/1FaNqBZ;
<brand>SitePoint</brand>
<publishDate>August 2005</publishDate>
<categoryAll/>
<originalTitle>A Really Good Introduction to XML</originalTitle>
<originalBody>A Really Good Introduction to XML —E. Berliet, Lyon, France
In this chapter, we’ll cover the basics of XML – essentially, most of the information you’ll need to know to get a handle on this exciting technology. After we’re done exploring some terminology and examples, we’ll jump right in and start working with XML documents. Then, we’ll spend some time starting the project we’ll develop through the course of this book: building an XML-powered content management system.
This excerpt is taken from No Nonsense XML Web Development with PHP, SitePoint’s new release, by Thomas Myer, which was designed to help you start using XML to build intelligent ‘Future-Proof’ PHP applications today.</originalBody>
<standardTitle>A Really, Really, Really Good Introduction to XML</standardTitle>
<standardSubtitle>Starting out right</standardSubtitle>
<standardPublishDate>8/24/2005</standardPublishDate>
<standardBody>A Really, Really, Really Good Introduction to XML —E. Berliet, Lyon, France
In this chapter, we’ll cover the basics of XML – essentially, most of the information you’ll need to know to get a handle on this exciting technology. After we’re done exploring some terminology and examples, we’ll jump right in and start working with XML documents. Then, we’ll spend some time starting the project we’ll develop through the course of this book: building an XML-powered content management system.
This excerpt is taken from No Nonsense XML Web Development with PHP, SitePoint’s new release, by Thomas Myer, which was designed to help you start using XML to build intelligent ‘Future-Proof’ PHP applications today.
The title contains over 350 pages of XML and PHP goodies. It walks you through the process of building a fully-functional XML-based content management system with PHP. And all the code used in the book is available to customers in a downloadalbe archive.
To find out more about “No Nonsense XML Web Development with PHP”, visit the book’s information page, or review the contents of the entire publication. As always, you can download this excerpt as a PDF if you prefer.</standardBody>
<standardNotes/>
<standardLastUpdated/>
<standardLastReviewed/>
<batchID>4127</batchID>
<batchPartnerID>1101</batchPartnerID>
<batchPartnerName>First Client Name</batchPartnerName>
</contentitem>
</content>
XSLT stylesheet drops children instead of renaming them
Aucun commentaire:
Enregistrer un commentaire