Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing parameters? #17

Open
UgmaDevelopment opened this issue May 23, 2020 · 1 comment
Open

Passing parameters? #17

UgmaDevelopment opened this issue May 23, 2020 · 1 comment

Comments

@UgmaDevelopment
Copy link

Hello!

Is there a way to pass parameters to the engine?

Here's an example that might clarify what I mean. Suppose you want to change the date in a file to the current date; using xsltransform.net, how could you pass that date in as a parameter?

Here's some XSL to illustrate my example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <!-- Here we declare the parameter that we expect to be passed in. -->
    <xsl:param name="currentDate"/>
    
    <!-- This block copies the whole thing (the input) into the output. -->
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
  

    <!-- This block replaces the `date_created` attribute of the Message element with the current date. -->
    <xsl:template match="/Message/@date_created">
        <!-- The name attribute is required, so we just specify the same name as before. `name()` uses the same name the attribute had previously; we don't want to change the attribute name, just its value. -->
        <xsl:attribute name="{name()}"> 
            <xsl:value-of select="$currentDate"/>
        </xsl:attribute>
    </xsl:template>
    
    
</xsl:stylesheet>

Thank you for efforts in making your useful tool public.

@joepjoosten
Copy link
Owner

Hi Bradley,

It's indeed not possible to set parameters when the template is called. You could just set the value attribute in the parameter, which will act as a default value. You could pass a value via the XML input, and select that as the default value.

Hope this helps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants