Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Updated

From: "Daniel" <softwareengineer98037@-----.--->
To: NULL
Date: 10/5/2004 3:17:00 PM
Got something that works but is veryslow because it reselects the source
document to get the friend attribute instead of just passing through once
and getting the friend attributes when making the kIsMappable key. Perhaps
you know of some way to speed this up by passing through the source document
just once to pull the friend attributes

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="kDistinctID" match="/*/*/*/@*" use="."/>
<xsl:key name="kIsMappable" match="@*[. = 'mappable']"
use="concat(generate-id(..),'|',name())"/>
<xsl:variable name="idsunique" select="/*/*/*/@*[name() = 'id' or
key('kIsMappable',concat(generate-id(../..),'|',name()))][generate-id() =
generate-id(key('kDistinctID',.)[name() = 'id'or
key('kIsMappable',concat(generate-id(../..),'|',name()))])]" />
<xsl:variable name="friends" select="/*/*/*/@*[name() = 'friend']"/>
<xsl:variable name="ids" select="/*/*/*/@*[name() = 'id']"/>
<xsl:template match="/">
  <uniques>
    <xsl:for-each select="$idsunique">
     <xsl:variable name="varid" select="."/>
     <xsl:variable name="curfriend" select="/*/*/*[@id = $varid]"/>
        <xsl:choose>
      <xsl:when test="$curfriend">
    <unique id="{.}" friend="{$curfriend/@friend}"/>
      </xsl:when>
      <xsl:otherwise>
         <unique id="{.}"/>
      </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
  </uniques>
</xsl:template>
</xsl:stylesheet>


The test case I tested on this xsl was:

<foo>
     <xs a="mappable" b="mappable" c="mappable" house="home">
         <x id="1111" friend="11" a="2222" c="3333" house="home" />
         <x id="4444" friend="22" a="5555" c="6666" house="home" />
     </xs>
     <ys j="mappable">
         <y id="7777" friend="33" j="8888" house="home" />
     </ys>
     <xs a="mappable" b="mappable" c="mappable" house="home">
         <x id="9999" friend="44" a="10-10" c="11-11" house="home" />
         <x id="12-12" friend="55" c="13-13" house="home" />
     </xs>
 </foo>

to

<?xml version="1.0" encoding="UTF-16"?>
<uniques>
    <unique id="1111" friend="11" />
    <unique id="2222" />
    <unique id="3333" />
    <unique id="4444" friend="22" />
    <unique id="5555" />
    <unique id="6666" />
    <unique id="7777" friend="33" />
    <unique id="8888" />
    <unique id="9999" friend="44" />
    <unique id="10-10" />
    <unique id="11-11" />
    <unique id="12-12" friend="55" />
    <unique id="13-13" />
</uniques>




"Daniel" <softwareengineer98037@y...> wrote in message
news:eueNgdyqEHA.3876@T......
> I modified yours and found something that almost works for the friend
> feature:
>
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:key name="kDistinctID" match="/*/*/*/@*" use="."/>
> <xsl:key name="kIsMappable" match="@*[. = 'mappable']"
> use="concat(generate-id(..),'|',name())"/>
> <xsl:variable name="idsunique" select="/*/*/*/@*[name() = 'id' or
> key('kIsMappable',concat(generate-id(../..),'|',name()))][generate-id() =
> generate-id(key('kDistinctID',.)[name() = 'id'or
> key('kIsMappable',concat(generate-id(../..),'|',name()))])]" />
> <xsl:variable name="friends" select="/*/*/*/@*[name() = 'friend']"/>
> <xsl:variable name="ids" select="/*/*/*/@*[name() = 'id']"/>
> <xsl:template match="/">
>   <uniques>
>     <xsl:for-each select="$idsunique">
>      <xsl:variable name="curfriend" select="/*/*/*[@id = '1111']"/>
>         <xsl:choose>
>       <xsl:when test="$curfriend">
>     <unique id="{.}" friend="{$curfriend/@friend}"/>
>       </xsl:when>
>       <xsl:otherwise>
>          <unique id="{.}"/>
>       </xsl:otherwise>
>     </xsl:choose>
>     </xsl:for-each>
>   </uniques>
> </xsl:template>
> </xsl:stylesheet>
>
> However it doesnt work cus the @id condition is hard coded to '1111'
>  <xsl:variable name="curfriend" select="/*/*/*[@id = '1111']"/>
>
> I tried  <xsl:variable name="curfriend" select="/*/*/*[@id = '{.}']"/> to
> try to get to just the current node rather then the one with an id of
'1111'
> but it didnt work. Any ideas? prehaps a small change around *[@id =
'{.}']"/
> ?
>
>
>
> "Daniel" <softwareengineer98037@y...> wrote in message
> news:%23J%23Pr5wqEHA.2340@T......
> > Thanks! That was perfect! You are the XSL Master!
> >
> > Another question: What if there was an attribute called "FRIEND" which
> > needed to be persisted for every persisted "id" in the source document
to
> > the target document. For example:
> >
> > <foo>
> >      <xs a="mappable" b="mappable" c="mappable">
> >          <x id="1111" FRIEND="1111 FRIEND BOB" a="2222" c="3333"
> > house="home">
> >           <x id="4444" FRIEND="4444 FRIEND ALEX" a="5555" c="6666"
> > house="home">
> >      </xs>
> >      <ys j="mappable">
> >          <y id="7777" FRIEND="7777 FRIEND JANET" j="8888" house="home">
> >      </ys>
> >  </foo>
> >
> >  to
> >
> >  <uniques>
> >      <unique id="1111" FRIEND="1111 FRIEND BOB">
> >      <unique id="2222">
> >      <unique id="3333">
> >      <unique id="4444" FRIEND="4444 FRIEND ALEX">
> >      <unique id="5555">
> >      <unique id="6666">
> >      <unique id="7777" FRIEND="7777 FRIEND JANET">
> >      <unique id="8888">
> >  </uniques>
> >
> > But 2222, 3333, 5555, 6666 and 8888 never have a friend cus they are
from
> > mappables
> >
> >
> > "Marrow" <m--a-r-r-o-w@m-a-r-r-o-w--s-o-f-t.com> wrote in message
> > news:OR7en8sqEHA.2724@T......
> > > Hi,
> > >
> > > Something like...
> > >
> > > <?xml version="1.0"?>
> > > <xsl:stylesheet version="1.0"
> > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> > >
> > > <xsl:key name="kDistinctID" match="/*/*/*/@*" use="."/>
> > >
> > > <!-- key for determining if a given attribute has an an attribute in
> > its -->
> > > <!--  parent/parent with the same name and a value of 'mappable' -->
> > > <xsl:key name="kIsMappable" match="@*[. = 'mappable']"
> > > use="concat(generate-id(..),'|',name())"/>
> > >
> > > <xsl:template match="/">
> > >   <uniques>
> > >     <xsl:for-each select="/*/*/*/@*[name() = 'id' or
> > >
key('kIsMappable',concat(generate-id(../..),'|',name()))][generate-id()
> =
> > > generate-id(key('kDistinctID',.)[name() = 'id' or
> > > key('kIsMappable',concat(generate-id(../..),'|',name()))])]">
> > >       <unique id="{.}"/>
> > >     </xsl:for-each>
> > >   </uniques>
> > > </xsl:template>
> > > </xsl:stylesheet>
> > >
> > >
> > > HTH
> > > Marrow
> > > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
> > > http://www.topxml.com/Xselerator
> > >
> > >
> > > "Daniel" <softwareengineer98037@y...> wrote in message
> > > news:%235u3HcnqEHA.2924@T......
> > > > Let me re explain my question better then:
> > > >
> > > > Basically I would like there to be two ways for an attributes to get
> > into
> > > > the output document.
> > > > 1. If the attribute's elements parent has an attribute with the same
> > name
> > > > and a value of "mappable"
> > > > 2. If the attribute is named "id"
> > > >
> > > > As for this resulting list of id's I would like it to be a unique
> list.
> > > > For example:
> > > > <foo>
> > > >      <xs a="mappable" b="mappable" c="mappable">
> > > >          <x id="1111" a="2222" c="3333" house="home">
> > > >           <x id="4444" a="5555" c="6666" house="home">
> > > >      </xs>
> > > >      <ys j="mappable">
> > > >          <y id="7777" j="8888" house="home">
> > > >      </ys>
> > > >  </foo>
> > > >
> > > >  to
> > > >
> > > >  <uniques>
> > > >      <unique id="1111">
> > > >      <unique id="2222">
> > > >      <unique id="3333">
> > > >      <unique id="4444">
> > > >      <unique id="5555">
> > > >      <unique id="6666">
> > > >      <unique id="7777">
> > > >      <unique id="8888">
> > > >  </uniques>
> > > >
> > > >
> > >
> > >
> >
> >
>
>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent