2
\$\begingroup\$

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"?>
<input>Put your input here</input>

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?

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ This is much longer than taking input from a separate XML though isn't it? \$\endgroup\$ – Beta Decay Jul 14 '15 at 16:35
  • \$\begingroup\$ name is shorter than match and param name="p" is shorter than value-of select="p". So, no, not at all. \$\endgroup\$ – Nathan Merrill Jul 14 '15 at 16:38
  • \$\begingroup\$ So you don't count the template definition in your code? That could work \$\endgroup\$ – Beta Decay Jul 14 '15 at 16:41
  • \$\begingroup\$ 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. \$\endgroup\$ – Nathan Merrill Jul 14 '15 at 16:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .