Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > how to generate unique usernames?

Reply
Thread Tools

how to generate unique usernames?

 
 
sjangity@gmail.com
Guest
Posts: n/a
 
      09-16-2007
I am generating xml file that will populate users in a database.

assigned_to contains names of developers.
reporter contains names of quality engineers.

I can't simply just create users filtering by //assigned_to or //
reporter as there will be many DUPLICATES. Why? Well, developers are
also reporters AND usernames are unique in the database.

Sample XML:
-------------
<psychology>
<issue>
<assigned_to>bob</assigned_to>
<reporter>sjangity</reporter>
</issue>
<issue>
<assigned_to>daniel</assigned_to>
<reporter>bob</reporter>
</issue>
</psychology>

How would the xslt look like anyone have any ideas? In the above
sample, I want to be able to create 3 users in total (bob, sjangity,
daniel).

Note: bob is both a developer and a QA contact.

Thanks!

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-16-2007
wrote:

> <psychology>
> <issue>
> <assigned_to>bob</assigned_to>
> <reporter>sjangity</reporter>
> </issue>
> <issue>
> <assigned_to>daniel</assigned_to>
> <reporter>bob</reporter>
> </issue>
> </psychology>
>
> How would the xslt look like anyone have any ideas? In the above
> sample, I want to be able to create 3 users in total (bob, sjangity,
> daniel).



Here is a sample XSLT 1.0 stylesheet:

<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xslutput method="xml" indent="yes"/>

<xsl:key name="name" match="issue/*" use="."/>

<xsl:template match="/">
<users>
<xsl:apply-templates select="psychology/issue/*[generate-id() =
generate-id(key('name', .)[1])]"/>
</users>
</xsl:template>

<xsl:template match="issue/*">
<user><xsl:value-of select="."/></user>
</xsl:template>

</xsl:stylesheet>

XSLT 2.0 solution:

<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xslutput method="xml" indent="yes"/>

<xsl:template match="/">
<users>
<xsl:for-each-group select="psychology/issue/*" group-by=".">
<user>
<xsl:value-of select="current-grouping-key()"/>
</user>
</xsl:for-each-group>
</users>
</xsl:template>

</xsl:stylesheet>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
sjangity@gmail.com
Guest
Posts: n/a
 
      09-16-2007
Hi Martin,

I ran the XSLT 1.0 version against the sample xml file mentioned above
and I am getting an empty result post transformation. Are you sure
that does the trick?

Thanks again for your feedback.

/Sandeep

On Sep 16, 9:43 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> sjang...@gmail.com wrote:
> > <psychology>
> > <issue>
> > <assigned_to>bob</assigned_to>
> > <reporter>sjangity</reporter>
> > </issue>
> > <issue>
> > <assigned_to>daniel</assigned_to>
> > <reporter>bob</reporter>
> > </issue>
> > </psychology>

>
> > How would the xslt look like anyone have any ideas? In the above
> > sample, I want to be able to create 3 users in total (bob, sjangity,
> > daniel).

>
> Here is a sample XSLT 1.0 stylesheet:
>
> <xsl:stylesheet
> xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xslutput method="xml" indent="yes"/>
>
> <xsl:key name="name" match="issue/*" use="."/>
>
> <xsl:template match="/">
> <users>
> <xsl:apply-templates select="psychology/issue/*[generate-id() =
> generate-id(key('name', .)[1])]"/>
> </users>
> </xsl:template>
>
> <xsl:template match="issue/*">
> <user><xsl:value-of select="."/></user>
> </xsl:template>
>
> </xsl:stylesheet>
>
> XSLT 2.0 solution:
>
> <xsl:stylesheet
> xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="2.0">
>
> <xslutput method="xml" indent="yes"/>
>
> <xsl:template match="/">
> <users>
> <xsl:for-each-group select="psychology/issue/*" group-by=".">
> <user>
> <xsl:value-of select="current-grouping-key()"/>
> </user>
> </xsl:for-each-group>
> </users>
> </xsl:template>
>
> </xsl:stylesheet>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/



 
Reply With Quote
 
George Bina
Guest
Posts: n/a
 
      09-17-2007
hI Sandeep,

Martin's solutions work ok from my tests so make sure you are testing
exactly with the files XML and XSLT that were posted here. If you
still have problems let us know what processor you are using and how
you are performing the transformation.
One comment will be that the 2.0 solution can be also more easily
encoded as below, using distinct-values instead of for-each-group:

<xsl:for-each select="distinct-values(psychology/issue/*)">
<user><xsl:value-of select="."/></user>
</xsl:for-each>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-17-2007
wrote:

> I ran the XSLT 1.0 version against the sample xml file mentioned above
> and I am getting an empty result post transformation. Are you sure
> that does the trick?


That stylesheet is fine in my view, result for your sample input is

<users>
<user>bob</user>
<user>sjangity</user>
<user>daniel</user>
</users>

which is what you want I think.




--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
sqad
Guest
Posts: n/a
 
      09-17-2007
Odd, I ran it through Altova XMLSpy editor and didn't see anything
after transformation. I'll investigate.

Thanks, Martin.

On Sep 17, 5:46 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> sjang...@gmail.com wrote:
> > I ran the XSLT 1.0 version against the sample xml file mentioned above
> > and I am getting an empty result post transformation. Are you sure
> > that does the trick?

>
> That stylesheet is fine in my view, result for your sample input is
>
> <users>
> <user>bob</user>
> <user>sjangity</user>
> <user>daniel</user>
> </users>
>
> which is what you want I think.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Is there a unique method in python to unique a list? Token Type Python 9 09-09-2012 02:13 PM
list question... unique values in all possible unique spots ToshiBoy Python 6 08-12-2008 05:01 AM
Can we generate Unique ID from Java? Max Java 5 02-28-2004 03:00 PM
generate own unique sessionid instead standard asp.net 120bit sessionid Ronald ASP .Net 6 02-23-2004 08:03 AM



Advertisments