Solved

How to pass an input to xsltproc

Posted on 2015-01-27
7
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use question mark (?) in filename with html 25 98
Wordpress Cron - Send XML Data to external server FTP 3 33
Unexpected End of File 11 55
RPM creation 6 19
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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