# How to take input in XSLT?

I'm thinking of starting answering questions in XSLT, but I don't know what the standard method of input would be?

I'm thinking of an XML file like so:

<?xml version="1.0" encoding="ISO-8859-1"?>


And then you access the input by using the following code:

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

<xsl:template match="/">
<xsl:value-of select="input" />
</xsl:template>


What do the rest of you think?

The option you listed above would work, however we also accept functions, so either of the following is valid as well:

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

<!-- The following is a named template, which acts like a function -->
<xsl:template name="t">
<xsl:param name="p">
</xsl:template>

<!-- The following is actual function in XSLT. -->
<xsl:function name="f">
<xsl:param name="p">
</xsl:function>


As a side note, matched templates (as opposed to named templates) can also accept parameters, but requires more code to set them up.

• This is much longer than taking input from a separate XML though isn't it? – Beta Decay Jul 14 '15 at 16:35
• name is shorter than match and param name="p" is shorter than value-of select="p". So, no, not at all. – Nathan Merrill Jul 14 '15 at 16:38
• So you don't count the template definition in your code? That could work – Beta Decay Jul 14 '15 at 16:41
• If you are referring to <xsl:template match="/">, yes I'm not counting it, because an XSL file doesn't need one. It can simply create a function that other XSLT templates will import and call. – Nathan Merrill Jul 14 '15 at 16:42