xsl获取参数中的当前节点无效

来源:互联网 发布:财务分析需要哪些数据 编辑:程序博客网 时间:2024/05/22 09:39
通过XSL自动排版,调用参数,如果参数出现"./"当前节点如:demo.xsl引入param_demo.xsl

<xsl:variable name="book_chapter_section_parts_pa" select="./part[@pid='p1' or@pid='p2']"/>

则无效!

本人测试各种方法无效后,最后只能直接在xsl中修改demo.xsl:

 <xsl:for-eachselect="./part[@pid='p1' or @pid='p2']"><span id="part"></span></xsl:for-each>由于里面不能加属性,所以定义一个标签在里面

public class JieXiXSL { 

    public staticvoid testParseXMLData(String xmlFileName) throws Exception { 

      try {

     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

      

       DocumentBuilder db = dbf.newDocumentBuilder();

       Document doc = (Document) db.parse(xmlFileName);

       NodeList list = doc.getElementsByTagName("span");

       for (inti = 0; i < list.getLength(); i++) {

        Element ele = (Element) list.item(i);

        String brandName =ele.getAttribute("id");

        System.out.println(brandName);

        if (brandName.equals("part")) {

        ele = (Element)ele.getParentNode();

        System.out.println(ele.getAttribute("select"));

         ele.setAttribute("select","./part[@pid='p1' or @pid='p23']");

        }

       }

       TransformerFactory transformerFactory = TransformerFactory.newInstance();

       Transformer transformer = transformerFactory.newTransformer();

       DOMSource domSource = new DOMSource(doc);

       // 设置编码类型

       transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");

       StreamResult result = new StreamResult(new FileOutputStream(xmlFileName));

       

       transformer.transform(domSource,result);

     

      }catch (Exceptionex) {

       ex.printStackTrace();

      }

    } 



    public staticvoid main(String args[]){ 

        try {

testParseXMLData("C:/Users/hewei/Desktop/fotr_yinwen.xsl");

} catch (Exceptione) {

e.printStackTrace();

    } 

}





0 0
原创粉丝点击