How to pass the value of an XSL parameter?

Suppose I have XSL as follows:

<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="1.0">
  <xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" indent="yes"/>
    <xsl:param name="sortKey" select="'firstname'"/>
</xsl:stylesheet>

Then XML as follows

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="XYZ.xsl"?>
<ABC>
     <firstname>GREG</firstname>
</ABC>

I want to pass a value to the XSL XML parameter firstname . I can do it? If so, how?

From the answers it is clear that this is impossible.

How about reading a value from the same XML and assigning it to a parameter. It can be done? If so, how?

+2
source share
3 answers

Since the value you want as a parameter is in basic XML, you can simply enter an XPath expression for the parameter that indicates the default value.

<xsl:param name="sortKey" select="/ABC/firstname"/> 

Just using a variable will also take place here if the value is always in XML

<xsl:variable name="sortKey" select="/ABC/firstname"/> 

, /, -

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

GREG

+5

, .NET , : XSLT .NET

+1

W3C . , . , , .

- "" , - document() function.

+1
source

Source: https://habr.com/ru/post/1747136/


All Articles