Re: [xsl] user defined data elements in stylesheets

Subject: Re: [xsl] user defined data elements in stylesheets
From: "Geert Bormans geert@xxxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 6 Dec 2019 11:11:35 -0000
Hi Mukul, 

is what you are looking for 
It has some issues however. 
It is an interesting hack in XSLT1 if you want to avoid the use of a node-set() function 
But I see no reason why you would not just put the data elements inside a variable (gives you some typing on top if you want) 

Met vriendelijke groeten, 
Best regards, 

Geert Bormans 

Van: "Abel Braaksma, (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 
Aan: "xsl-list" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> 
Verzonden: Vrijdag 6 december 2019 11:55:47 
Onderwerp: [xsl] user defined data elements in stylesheets 

Hi all, 
I'm trying to use 'user defined data elements' in an XSLT stylesheet. 

Following is my XSLT transformation example, 

XML input document: 

<?xml version="1.0" encoding="UTF-8"?> 
<a val="-1"/> 
<a val="-4"/> 
<a val="5"/> 
<a val="3"/> 
<a val="2"/> 

XSLT stylesheet (file proc1.xsl, with local absolute URI file:///e:/xslt_examples/basic/proc1.xsl): 

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl=" [ | ] " 
xmlns:m_ns0=" [ | ] " 

<xsl:output method="xml" indent="yes"/> 
<!-- this is the user defined data element --> 

<xsl:template match="root"> 
<xsl:copy-of select="document('file:///e:/xslt_examples/basic/proc1.xsl')/xsl:stylesheet/m_ns0:names" copy-namespaces="no"/> 
<xsl:apply-templates select="a[number(@val) gt 0]" mode="gt0"/> 
<xsl:apply-templates select="a[number(@val) lt 0]" mode="lt0"/> 

<xsl:template match="a" mode="gt0"> 
<val><xsl:value-of select="@val"/>: positive</val> 

<xsl:template match="a" mode="lt0"> 
<val><xsl:value-of select="@val"/>: negative</val> 


The above transformation produces, following result, 

<?xml version="1.0" encoding="UTF-8"?> 
<m_ns0:names xmlns:m_ns0=" [ | ] "> 
<val>5: positive</val> 
<val>3: positive</val> 
<val>2: positive</val> 
<val>-1: negative</val> 
<val>-4: negative</val> 

The above output is what I'm expecting. 

Following are my questions, 

You could see that, within my stylesheet, I've used following stylesheet instruction, 
<xsl:copy-of select="document('file:///e:/xslt_examples/basic/proc1.xsl')/xsl:stylesheet/m_ns0:names" copy-namespaces="no"/> 

I've used the absolute URI of the stylesheet document, as argument to the document() function. Is it possible, to specify the stylesheet document reference to the document() function in a portable way (i.e, not an absolute URI)? 

Mukul Gandhi 
[ | 
XSL-List info and archive ] 
[ | EasyUnsubscribe ] ( [  | by email ] ) 

Current Thread