Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Updated >Thread Next - Re: Updated Re: UpdatedTo: NULL Date: 10/5/2004 3:08:00 PM 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>
> > >
> > >
> >
> >
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
