xsl-list
[Top] [All Lists]

Re: [xsl] Combining two XBEL XML files

2008-07-12 12:34:42
Here is an attempt in XSLT 2.0 but I have no files to test that with so that is completely untested. The primary input document should be one bookmark file, the URL of the second should be passed in as the parameter sec-file:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:my="http://example.com/2008/my";
  exclude-result-prefixes="my"
  version="2.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:param name="sec-file" select="'bookmark2.xml'"/>
  <xsl:variable name="sec-doc" select="doc($sec-file)"/>

  <xsl:function name="my:folder-merge" as="element()*">
    <xsl:param name="folders" as="element()*"/>
    <xsl:for-each-group select="$folders" group-by="title">
      <xsl:sort select="current-grouping-key()"/>
      <folder>
        <title>
          <xsl:value-of select="current-grouping-key()"/>
        </title>
        <xsl:sequence select="my:folder-merge(current-group()/folder)"/>
<xsl:sequence select="my:bookmark-merge(current-group()/bookmark)"/>
      </folder>
    </xsl:for-each-group>
  </xsl:function>

  <xsl:function name="my:bookmark-merge" as="element()*">
    <xsl:param name="bookmarks" as="element()*"/>
    <xsl:for-each-group select="$bookmarks" group-by="@href">
      <xsl:sort select="current-group()[1]/title"/>
      <xsl:sequence select="current-group()[1]"/>
    </xsl:for-each-group>
  </xsl:function>

  <xsl:template match="xbel">
    <xsl:copy>
<xsl:sequence select="my:folder-merge(folder | $sec-doc/xbel/folder)"/> <xsl:sequence select="my:bookmark-merge(bookmark | $sec-doc/xbel/bookmark)"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Martin,

Looks like it is generally working. it is not picking up bookmarks that are in general <xbel> scope without being in a <folder>. And also the XBEL header is not there but other than that greatstuff thanks alot.

It just needs some minor pragmatics like master outer scope <title> dealing with allowing overriding from command line, or choosing from specific document. And if two bookmark titles are the same but the URL's are different then including both bookmarks.

Whats the differences that stop it running on 1.0 ?

Cheers Martin this is looking great, I will have to sit down with a print out and my XSLT manual and see if I can get to understand it. Thanks,

Aaron


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--