我需要使用xalan重定向擴展將新元素添加到現有xml文件中,但是我遇到了命名空間問題。XSLT:添加新元素時排除名稱空間
my xslt :
<xsl:stylesheet version="1.0"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
extension-element-prefixes="redirect" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:validator="xalan://com.epam.app.transformation.Validator"
xmlns:t="http://www.products.com" exclude-result-prefixes="#default t">
<xsl:import href="addProductPage.xsl" />
<xsl:param name="name"></xsl:param>
<xsl:param name="provider"></xsl:param>
<xsl:param name="model"></xsl:param>
<xsl:param name="color"></xsl:param>
<xsl:param name="dateOfIssue"></xsl:param>
<xsl:param name="notInStock"></xsl:param>
<xsl:param name="price"></xsl:param>
<xsl:param name="filename"></xsl:param>
<xsl:param name="isValid"
select="validator:validateFields($name, $provider, $model, $dateOfIssue, $color,$price,$notInStock)" />
<xsl:param name="categoryName"></xsl:param>
<xsl:param name="subcategoryName"></xsl:param>
<xsl:output omit-xml-declaration="yes" indent="no" />
<xsl:template match="/" priority="2">
<html>
<head>
<title>Products Home Page</title>
</head>
<body>
<xsl:choose>
<xsl:when test="$isValid">
<redirect:write select="$filename" append="false">
<xsl:call-template name="saveProduct" />
</redirect:write>
<xsl:call-template name="returnToProducts" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="addProduct" />
<!-- i show errors in here -->
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:template>
<xsl:template name="saveProduct" match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template
match="/t:categories/t:category[@name=$categoryName]/t:subcategory[@name=$subcategoryName]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="product">
<xsl:attribute name="name">
<xsl:value-of select="$name" />
</xsl:attribute>
<xsl:element name="provider">
<xsl:value-of select="$provider" />
</xsl:element>
<xsl:element name="model">
<xsl:value-of select="$model" />
</xsl:element>
<xsl:element name="color">
<xsl:value-of select="$color" />
</xsl:element>
<xsl:element name="dateOfIssue">
<xsl:value-of select="$dateOfIssue" />
</xsl:element>
<xsl:choose>
<xsl:when test="$notInStock">
<xsl:element name="notInStock" />
</xsl:when>
<xsl:otherwise>
<xsl:element name="price">
<xsl:value-of select="$price" />
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:copy>
</xsl:template>
<xsl:template name="returnToProducts">
<html>
<head>
<meta http-equiv="refresh"
content="0;url=controller?command=GetProductsCmd&categoryName={$categoryName}&subcategoryName={$subcategoryName}" />
</head>
</html>
</xsl:template>
</xsl:stylesheet>
我得到下一個輸出中:
<product xmlns="" name="camera"><provider>pro</provider><model>AB200</model><color>black</color><dateOfIssue>06-01-2014</dateOfIssue><price>1000</price></product>
,但我需要沒有指定命名空間的所有元素這樣<product name="camera">..etc..</product>
任何建議,將不勝感激
您能否包含您正在使用的_input_ XML示例?我懷疑這個輸入有一個'xmlns =「東西」'那正在阻礙你。 –