Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 9th, 2003, 12:08 AM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to loop through a HashMap in XSL?

Hi All,
I need to pass a set of dynamic filter conditions to XSL file from Java program. Hence, I created a HashMap of filter conditions and passed them from Java program to XSL file. How do I loop through that HashMap in XSL to retrieve the key-value pairs?
Thanks and Regards,
Sunil.
Reply With Quote
  #2 (permalink)  
Old December 9th, 2003, 12:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Quote:
quote:Originally posted by sunilnk
 Hi All,
I need to pass a set of dynamic filter conditions to XSL file from Java program. Hence, I created a HashMap of filter conditions and passed them from Java program to XSL file. How do I loop through that HashMap in XSL to retrieve the key-value pairs?
Thanks and Regards,
Sunil.
What you can pass to XSLT stylesheet are so called stylesheet parameters. For example, in the command line you can write:
Code:
saxon source.xml sheet.xsl param1=value1 param2=value2 ...
However, it's impossible to dynamically change XPath expressions (as I understand, you want to dynamically create predicates) in stylesheets. Post your stylesheet source and say what you want to do exactly, and we'll try to find a solution.

Regards,
Armen
Reply With Quote
  #3 (permalink)  
Old December 9th, 2003, 01:23 AM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here are the details:
My main requirement is to pass a set of filter parameters to the XSL dynamically. I am using the XALAN processor.
I am trying to pass the HashMap of filters from Java program as follows:

            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer(new StreamSource("coltest.xsl"));

            HashMap paramMap = new HashMap();
            paramMap.put("country", "EU");
            paramMap.put("title", "Mac");
            transformer.setParameter("parameters", paramMap);
            transformer.transform(new StreamSource("catalog.xml"),new StreamResult(System.out));

The XSL file is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xalan"
    xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">

<xsl:output method="html" />
<xsl:param name="parameters" select="java:java.util.HashMap.new" />

<xsl:template match="/">
    <html>
        <body>
            <table border="2" bgcolor="yellow">
                <tr>
                    <th>Title</th>
                    <th>Artist</th>
                <xsl:apply-templates select="catalog/cd">
                    <xsl:with-param name="parameters" select="$parameters" />
                </xsl:apply-templates>
                </tr>
            </table>
        </body>
    </html>
</xsl:template>

<xsl:template match="cd">



<xsl:variable name="keys" select="java:keySet($parameters)" />

<xsl:for-each select="$keys">

</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

Let me know if this feasible using XSL.
If not, what is a viable solution to pass filter conditions dynamically - both tag name and value for that being dynamic.

Thanks and Regards,
Sunil.
Reply With Quote
  #4 (permalink)  
Old December 10th, 2003, 12:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Sorry for the late response: I was busy...

So, Xalan (2.5.2, for example) gives you an opportunity to write your own extensions.
Read first this: http://xml.apache.org/xalan-j/extensions.html.
You can manipulate the HashTable like this: http://xml.apache.org/xalan-j/extensions.html#ex-java .
This example will help you to accomplish your work. The drawback of your stylesheet is that it depends on the concrete XSLT processor.

Regards,
Armen
Reply With Quote
  #5 (permalink)  
Old December 15th, 2003, 04:28 AM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great... it worked! Thanks for the help.

Regards,
Sunil.

Reply With Quote
  #6 (permalink)  
Old April 10th, 2017, 12:54 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2017
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question read values from hashmap in xslt

i tried reading setting hashmap at jav end and use that map in my XSLT and generate dynamic values. But it didnot work using saxon.
Reply With Quote
  #7 (permalink)  
Old April 10th, 2017, 04:09 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

swarna$, please don't add a completely new question to a thread that closed over 13 years ago. Ask a new question. And please say exactly what you were doing and exactly how it failed.

Also, unless your question is specifically about something you read in a Wrox book, the best place to get answers to XSLT coding questions these days is StackOverflow.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help: how can I break from xsl for-each loop ? back2grave XSLT 5 May 31st, 2012 12:03 PM
XSL Loop and incrementing a variable 2007-03-29 XSLT 8 March 30th, 2007 10:41 AM
xsl:for-each loop Tomi XSLT 3 September 7th, 2006 05:35 AM
Loop in XSL NEO1976 XSLT 31 September 5th, 2006 03:39 AM
HashMap freezotic BOOK: Beginning Java 2 6 March 26th, 2004 03:27 PM



All times are GMT -4. The time now is 02:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.