Get username

Here should go questions about transforming XML with XSLT and FOP.
Rumplestiltzkin
Posts: 28

Get username

Thu Jun 24, 2010 3:36 pm

Is there any way I can get the windows username of the user running a stylesheet?
adrian
Posts: 2461

Re: Get username

Thu Jun 24, 2010 3:59 pm

Hello,

You can't do this in the stylesheet, the username has to be obtained from outside. You can either write a Java extension function that obtains it and then invoke this extension in the stylesheet to obtain it for you or you can obtain the username from outside before the transformation and pass it to the stylesheet as a parameter.

The first is a bit more complicated and involves a bit of Java code.

The second is a lot more simple and can be easily used in Oxygen:
- add to your stylesheet a new param: <xsl:param name="username"/>
- use the $username parameter as you need in the stylesheet.
- In Oxygen configure your transformation scenario: Document -> Transformation -> Configure Transformation Scenario, press Parameters and add(or edit if you can already see it listed) your parameter(username) and give it the value: ${system(user.name)}

When you apply the transformation Oxygen will evaluate the "user.name" Java system property and pass it to the stylesheet as the "username" parameter.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
shudson310
Posts: 130
Location: USA

Re: Get username

Sat Dec 10, 2016 8:07 pm

Does this also work for schematron? Is there a way to get the current user in schematron?
Scott Hudson
Content Strategist
Jeppesen
Site: jeppesen.com
tavy
Posts: 155

Re: Get username

Mon Dec 12, 2016 11:29 am

Hello,

Yes, you can obtain the current user name also in Schemtron. You have two solutions:
  1. The first one is to use the "system-property()" function, something like this:

    Code: Select all

    <xsl:value-of select="system-property('user.name')"/>

    We are using Saxon processor to validate an XML with a Schematron schema, and Saxon implementation of the "system-property()" function will return also the value of a Java system property.
    http://www.saxonica.com/html/documentation/functions/fn/system-property.html
  2. The second solution is to implement a Java extension function, as Adrian also explained, and add the JAR file in the extension dialog from the the Schematron validation scenario.
    https://www.oxygenxml.com/doc/versions/18.1/ug-editor/tasks/create-validation-scenario.html

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests