on 05-16-2006 11:26 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.