1
我有我的XSL文件模板「printRestrictions」改造給定的參數,以我的轉換器對象數組的數組:XSL不改變給定的參數
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="this xsl" version="1.0">
<xsl:output indent="yes"/>
<xsl:param name="destinationRestriction"/>
<xsl:template name="printRestrictions">
<xsl:param name="array"/>
<xsl:if test="$array">
<xsl:for-each select="$array/item">
<restriction><xsl:value-of select="@value"/></restriction>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="af:ascframe">
<ascstatistic>
<destination>
<restrictions>
<xsl:call-template name="printRestrictions">
<xsl:with-param name="array" select="$destinationRestriction"/>
</xsl:call-template>
</restrictions>
</destination>
</ascstatistic>
</xsl:template>
</xsl:stylesheet>
我給我的轉換器包含兩個項目的NodeList對象(org.w3c.dom)。
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("root");
doc.appendChild(rootElement);
Element child = doc.createElement("item");
child.setAttribute("value", "id1");
rootElement.appendChild(child);
Element child2 = doc.createElement("item2");
child2.setAttribute("value", "id2");
rootElement.appendChild(child2);
NodeList childrenRestrictionsIds = rootElement.getChildNodes();
但是在轉換之後,只有第一項被插入到我的輸出對象中。不是都。
任何幫助表示讚賞。
請向我們展示一個完整的工作XSLT樣式表,其中存在您的問題,包括輸入XML(如果有問題)。特別是'$ destinatonRestriction'的定義至關重要。 – 2014-10-17 12:09:47
將參數傳遞給樣式表的慣例取決於您正在使用的XSLT處理器。你沒有告訴我們。 – 2014-10-17 13:40:30