cancel
Showing results for 
Search instead for 
Did you mean: 

Retriving xsl atributes to a hashtable

Former Member
0 Kudos

Hi to you all,

I´m trying to develop a program that will read a xsl file and return me all the atributes eg:

I want to read this xsl and write it on a hashtable.

Is it possible? Because I don´t know where to start.

Best Regards

Natasha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI

SAP web as supports xsl Transformation in follwing ways

1)using the standard sun JAXP API

http://help.sap.com/saphelp_nw04/helpdata/en/4b/133a3e5069eb6ce10000000a114084/frameset.htm

http://java.sun.com/webservices/jaxp/dist/1.1/docs/api/

2)Java language binded with XSL

http://help.sap.com/saphelp_nw04/helpdata/en/26/227402890aa140ac967fe6000d93a1/frameset.htm

Hope this will at least guide to your req ,please let me know if you r looking for some more info

Please mark points for helpful answers

regards

rajeshkr

Former Member
0 Kudos

Hi, Rasjesh

This is a bit helpfull but not what I whant.

Thanks anyway

Natasha

Former Member
0 Kudos

Hi

Can you explain in more detail you req,for further analysis

regards

rajeshkr

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

Hi Natasha,

Try this:


try {
	SAXParserFactory factory = SAXParserFactory.newInstance();
	SAXParser parser = factory.newSAXParser();
	 
	StringReader sr = new StringReader(XSL.trim());
	InputSource is = new InputSource(sr);
	XSLDataHandler xslDataHandler = new XSLDataHandler();
	parser.parse(is, xslDataHandler);
	Hashtable attributes = xslDataHandler.getAttributes();
	
} catch (Exception e) {
}

private static final String XSL = 
		"<?xml version="1.0"?>"
		+ "<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">"
		+ "<xsl:for-each select="/Props">" 
		+ "<root>" 
		+ "<News>" 
		+ "<xsl:attribute name="Namesapace"><a href="http://com.sap/xmlns/cm" TARGET="test_blank">http://com.sap/xmlns/cm</a></xsl:attribute>" 
		+ "<xsl:attribute name="Prop">News</xsl:attribute>" 
		+ "<xsl:attribute name="Value">23</xsl:attribute>" 
		+ "</News>" 
		+ "</root>" 
		+ "</xsl:for-each>"
		+ "</xsl:stylesheet>";

	public class XSLDataHandler extends DefaultHandler {
		private Hashtable attributes = new Hashtable();
		private String lastAttribute;
		public void startElement(
			String namespaceURI,
			String localName,
			String rawName,
			Attributes atts) {
			if ("attribute".equals(localName)) {
				lastAttribute = atts.getValue("name");
			}
		}

		public void endElement(
			String namespaceURI,
			String localName,
			String rawName) {
			if ("attribute".equals(localName)) {
				lastAttribute = null;
			}
		}

		public void characters(char[] data, int off, int length) {
			if (null != lastAttribute) {
				final String value = new String(data, off, length).trim();
				if (!"".equals(value)) {
					attributes.put(lastAttribute, value);
				}
			}
		}

		private void setAttributes(Hashtable attributes) {
			this.attributes = attributes;
		}

		private Hashtable getAttributes() {
			return attributes;
		}
	}

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi,

I´ve got already the XSL file, I don´t want to create a "private static final String XSL", I want to retrive from a filesystem and then retrive the atributes that it has.

It is confusing

Best Regards

Natasha

Former Member
0 Kudos

Natasha,

use DOM to parse your xsl file and access the attributes via the DOM API.

<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM.html#wp79994">Java DOM Documentation</a>

Best regards

Sebastian

former_member182372
Active Contributor
0 Kudos

Hi Natasha,

instead of

StringReader sr = new StringReader(XSL.trim());
InputSource is = new InputSource(sr);

put


InputStream istream = this.getClass().getClassLoader().getResourceAsStream("com/sap/sdn/attributes.xsl");
InputSource is = new InputSource( istream );

Best regards, Maksim Rashchynski.