开发者

Removing an XML tag that is named like xfdf:field (with a namespace)

开发者 https://www.devze.com 2023-02-13 14:31 出处:网络
I want to remove an XML element from an XML file. The tag that I want to remove is named as xfdf:field.

I want to remove an XML element from an XML file. The tag that I want to remove is named as xfdf:field. How do I specify this in my xslt ? I tried this and I am getting an error saything "org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: xfdf ".

Here is my xslt.

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" />
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="xfdf:field"></xsl:template>
</xsl:stylesheet>

Here is my xml.

<xfa:datasets 
 xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
 xmlns:dd="http://ns.adobe.com/data-description/" xmlns:tns="http://hostname"
 xmlns:xfdf="http://ns.adobe.com/xfdf/">
    <xfa:data>
        <tns:form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <tns:formHeader>
                <tns:formId>formid</tns:formId>
                <tns:revId>Rev123</tns:revId>
                <tns:agencyId>agency</tns:agencyId>
                <tns:progId>program</tns:progId>
                <tns:serviceId>service</tns:serviceId>
            </tns:formHeader>
            <tns:formFields>
                <tns:date>08-13-1967</tns:date>
                <tns:agreementBetween></tns:agreementBetween>
                <tns:ncr>xxxx</tns:ncr>
                <tns:formConfirmationInfo>
                    <tns:confNbrLbl>nbrlabel</tns:confNbrLbl>
                    <tns:confNbrData>1231</tns:confNbrD开发者_运维知识库ata>
                    <tns:custNameLbl>3332</tns:custNameLbl>
                    <tns:custNameData>dasdas</tns:custNameData>
                    <tns:dateLbl>date</tns:dateLbl>
                    <tns:dateData>01012001</tns:dateData>
                </tns:formConfirmationInfo>
            </tns:formFields>
            <xfdf:field xmlns:xfdfi="http://ns.adobe.com/xfdf-transition/"
                        xfdfi:original="FSAPPLICATIONDATA_">
                <!--irrelevant data omitted-->
            </xfdf:field>
        </tns:form>
    </xfa:data>
</xfa:datasets>


You need to specify the namespace in your XSLT file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
        xmlns:xfdf="http://ns.adobe.com/xfdf/">
0

精彩评论

暂无评论...
验证码 换一张
取 消