Solved

How to pass an input to xsltproc

Posted on 2015-01-27
7
111 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
Comment Utility
<xsl:number format="{$site_number}" level="any"/>
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Author Comment

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

Assisted Solution

by:Geert Bormans
Geert Bormans earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
docker invalid registry name 2 45
LDAP find expired users 8 40
c# code 19 56
Changing passwords in Linux Systems 3 13
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

6 Experts available now in Live!

Get 1:1 Help Now