How to pass an input to xsltproc

I want to pass an input to xsltproc for the number function..

I am able to do it via strings to get a specific output, however i want a numbering sequence to start with what i have provided as input..

below is the sample xml and xsl . please help

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="site_name">Site1</xsl:param>
  <xsl:param name="site_number">100</xsl:param>
  <xsl:output method="text"/>
  <xsl:template match="Servers">
    <xsl:for-each select="//Server">
      <xsl:if test="Name=$site_name">
   <xsl:number format=$site_number level="any"/>
        <xsl:value-of select="User"/>
        <xsl:value-of select="Pass"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Open in new window


XML is

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Container>
    <Servers>
        <Folder expanded="1">
            <Server>
                <User>username1</User>
                <Pass>password1</Pass>
                <Name>Site1</Name>
            </Server>
            <Server>
                <User>username2</User>
                <Pass>password2</Pass>
                <Name>Site2</Name>
            </Server>
        </Folder>
        <Server>
            <User>username3</User>
            <Pass>password3</Pass>
            <Name>Site3</Name>
        </Server>
        <Server>
            <User>username4</User>
            <Pass>password4</Pass>
            <Name>Site4</Name>
        </Server>
    </Servers>
</Container>

Open in new window


expected output with the command

xsltproc --stringparam site_name "Site2" site_number "501" param.xsl param.xml

is
501username2password2
LVL 16
Wasim Akram ShaikAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
I misread the question

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="site_name">Site1</xsl:param>
    <xsl:param name="site_number">500</xsl:param>
    <xsl:output method="text"/>
    <xsl:template match="Servers">
        <xsl:apply-templates select="//Server[Name=$site_name]"/>
     </xsl:template>
    
    <xsl:template match="Server">
        <xsl:variable name="number">
            <xsl:number level="any"/>
        </xsl:variable>
        <xsl:value-of select="$site_number + $number"/>
        <xsl:value-of select="User"/>
        <xsl:value-of select="Pass"/>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
<xsl:number format="{$site_number}" level="any"/>
0
 
Wasim Akram ShaikAuthor Commented:
Thanks geert, i had got passed the input variable, but i have a situation here.. what am trying to achieve is you had already answered it earlier..

<xsl:number format="1" level="any" count="PersonNameDetails/PersonNames | EntityNameDetails/EntityNames"/>

what am actually trying to achieve is to go for a counter without this.. because i think the above counter is slowing down the processing speed.. (correct me if am wrong).. am trying to achieve a counter without this. where in i can increment the number sequentially..

the suggestion is again resetting the counter value.. pls suggest if you see any improvement in this..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Wasim Akram ShaikAuthor Commented:
Geert.. Even the latest comment is giving out an error..
0
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
First on performance.
I am not sure xsl:number should be slow.
Most xslt processors calculate them on parsing the document (it is a straightforward optimisation)
I think it beats using position()

You could use keys to get a performance optimisation, but I am not sure it would help

I am not sure what the error is, can you give more details?
0
 
Wasim Akram ShaikAuthor Commented:
Sorry for the delay.. Thanks for the answer..

Can you please shed some light on xsl:key, is it possible to generate sequence numbers

basically what am doing is am transforming a xml document to txt file

i just need a counter for every new line.. can key do this?, what i thought was counter using the <xsl:number> is impacting performance..

actually the file size is 38 mb.. its generating approximately 20k records with 35 columns overall(12 has data in them, rest are null and tab delimited)

its taking almost 22min 17 secs to complete.. thats where am looking out the bottlenecks so as to reduce this burden.. first i could see is the counter.. which when removed had given a improvement of around 5 mins.. ie., if there is no counter then xsltproc is completing in 17mins..
0
 
Geert BormansInformation ArchitectCommented:
I can't imagin why xslt-proc is working 22 minutes on a 35MB file
I am curious what your environment is, moving to saxon and XSLT 2 could help a fair amount, XSLT-Proc is really old
If you are running this from one of the C-languages (ruby, php, perl) however, there is little alternative

An approach that most likely will boost performance is seperation of concerns
Make your XSLT a multiple step process
- a first XSLT could be an identity transform that removes all the null values, the result wil be a substantially smaller XML
- use that XML to do all the required processing in a second step, including the numbers
Make sure that you don't serialise between steps
0
All Courses

From novice to tech pro — start learning today.