<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tb="http://eastgate.com/Tinderbox/maparent"
  xmlns:rpc="http://maparent.webhop.net/xmlrpc"
  xsl:extension-element-prefixes="tb rpc"
  version="1.0">

  <xsl:param name="callingNode"/>

  <xsl:variable name="catProto" select="rpc:callingNode()/ancestor::tinderbox//item[tb:property('IsPrototype') = 'true' and tb:property('Name') = 'Category']"/>

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:template match="*">
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="struct">
    <xsl:variable name="newId" select="tb:newId()"/>
    <item Creator="system">
      <xsl:attribute name="ID">
        <xsl:value-of select="$newId"/>
      </xsl:attribute>
      <attribute name="Name">
        <xsl:value-of select="member[name/text()='title']/value/string/text()"/>
      </attribute>
      <attribute name="catId">
        <xsl:value-of select="member[name/text()='id']/value/int/text()"/>
      </attribute>
    </item>
    <tb:declareNewLink name="'prototype'" sourceid="$catProto" destid="$newId" destcreator="'system'"/>
  </xsl:template>

</xsl:stylesheet>

