Solved

How to pass an input to xsltproc

Posted on 2015-01-27
7
114 Views
Last Modified: 2015-01-28
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
0
Comment
Question by:Wasim Akram Shaik
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40573251
<xsl:number format="{$site_number}" level="any"/>
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 40573283
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
 
LVL 16

Author Comment

by:Wasim Akram Shaik
ID: 40573324
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 16

Author Comment

by:Wasim Akram Shaik
ID: 40574435
Geert.. Even the latest comment is giving out an error..
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 500 total points
ID: 40574615
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
 
LVL 16

Author Closing Comment

by:Wasim Akram Shaik
ID: 40575387
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40575973
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

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now