Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Can someone help me with the following:

 

I want to extract <loc>, <lastmod> and <priority> from this xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>http://www.myurl.com/</loc><lastmod>2014-04-03T15:51:51-05:00</lastmod><priority>1.0</priority></url>
<url><loc>http://www.myurl.com/for-sale/TX/100/79109/173-Main-094451242</loc><lastmod>2014-04-07T03:09:00-05:00</lastmod><priority>0.7</priority></url>
<url><loc>http://www.myurl.com/for-sale/TX/100/79109/146-Main-098844556</loc><lastmod>2014-04-07T02:48:00-05:00</lastmod><priority>0.7</priority></url>
<url><loc>http://www.myurl.com/for-sale/TX/100/79109/353-Main-188745469</loc><lastmod>2014-04-07T02:31:00-05:00</lastmod><priority>0.7</priority></url>
</urlset>

 

I am using this stylesheet (which is not working):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>

<PRODUCT BUILD="" NAME="FileMaker" VERSION="ProAdvanced 12.0v4"/>
<DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="loc" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="lastmod" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="priority" TYPE="TEXT" />
</METADATA>

<RESULTSET FOUND="">
<xsl:for-each select="//url">
<ROW RECORDID="" MODID="" >
<COL><DATA><xsl:value-of select="loc"/></DATA></COL>
<COL><DATA><xsl:value-of select="lastmod"/></DATA></COL>
<COL><DATA><xsl:value-of select="priority"/></DATA></COL>
</ROW>
</xsl:for-each>

</RESULTSET>
</FMPXMLRESULT>
</xsl:template>
</xsl:stylesheet>

 

Thanks very much.

First thing: please use the "code" formatting when posting XML code, to make it readable:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.myurl.com/</loc>
      <lastmod>2014-04-03T15:51:51-05:00</lastmod>
      <priority>1.0</priority>
   </url>
   <url>
      <loc>http://www.myurl.com/for-sale/TX/100/79109/173-Main-094451242</loc>
      <lastmod>2014-04-07T03:09:00-05:00</lastmod>
      <priority>0.7</priority>
   </url>
   <url>
      <loc>http://www.myurl.com/for-sale/TX/100/79109/146-Main-098844556</loc>
      <lastmod>2014-04-07T02:48:00-05:00</lastmod>
      <priority>0.7</priority>
   </url>
   <url>
      <loc>http://www.myurl.com/for-sale/TX/100/79109/353-Main-188745469</loc>
      <lastmod>2014-04-07T02:31:00-05:00</lastmod>
      <priority>0.7</priority>
   </url>
</urlset>

Now, the reason why your stylesheet cannot work is that the source XML has a namespace of its own, declared in the root element:

xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"

All the elements descendant of the root element inherit this namespace. As a result, all your XPath expressions:

select="//url" 
select="loc" 
etc.

select nothing.

 

 

You need to declare the namespace in your stylesheet, assign it a prefix, and use that prefix when calling the elements in your XML:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:smp="http://www.sitemaps.org/schemas/sitemap/0.9">

<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="/">

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>

<PRODUCT BUILD="" NAME="FileMaker" VERSION="ProAdvanced 12.0v4"/>
<DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="loc" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="lastmod" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="priority" TYPE="TEXT" />
</METADATA>

<RESULTSET FOUND="">
<xsl:for-each select="//smp:url">
<ROW RECORDID="" MODID="" >
<COL><DATA><xsl:value-of select="smp:loc"/></DATA></COL>
<COL><DATA><xsl:value-of select="smp:lastmod"/></DATA></COL>
<COL><DATA><xsl:value-of select="smp:priority"/></DATA></COL>
</ROW>
</xsl:for-each>

</RESULTSET>
</FMPXMLRESULT>
</xsl:template>
</xsl:stylesheet>

Note also that performance-wise, it pays to be explicit in XSLT. It's better to say:

<xsl:for-each select="smp:urlset/smp:url">

than just:

<xsl:for-each select="//smp:url">
  • Author

Excellent.  Thank you so much, Comment.  As usual... works like a charm.

  • 3 weeks later...

Glad it worked! I'd change comment's excellent code like this (two snippets):

1. if you use/create an xmlns for the source, then remember to exclude it from the output.

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:smp="http://www.sitemaps.org/schemas/sitemap/0.9"
   exclude-result-prefixes="smp">

2. if you have 'relative' path for the child elements, the parent xmlns is only required.

<RESULTSET FOUND="">
   <xsl:for-each select="//smp:url">
      <ROW RECORDID="" MODID="" >
         <COL><DATA><xsl:value-of select="./loc"/></DATA></COL>
         <COL><DATA><xsl:value-of select="./lastmod"/></DATA></COL>
         <COL><DATA><xsl:value-of select="./priority"/></DATA></COL>
      </ROW>
   </xsl:for-each>

:cool:

1. if you use/create an xmlns for the source, then remember to exclude it from the output.

 

2. if you have 'relative' path for the child elements, the parent xmlns is only required.

 

Re #1, it makes no practical difference, but perhaps as a point of good practice...

 

Alas, you could not be more wrong re #2. So who are you and what have you done to the real Beverly Voth, the author of FileMaker Pro 6 Developer's Guide to XML/XSL - who BTW would also not write "./loc" when "loc" is quite sufficient?

LOL! 'as a point of good practice' for both 1 & 2 ? :grad: mostly tried-and-true with what works well in FMP since v6 and still works well in v13!!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.