我想用xslt替換元素標記名稱。我有一個輸出這樣的:如何使用xslt更改父標記中元素的文本
<gl-cor:documentInfo>
<gl-cor:entriesType contextRef="journal_context">DocumentID</gl-cor:entriesType>
<gl-cor:uniqueID contextRef="journal_context">RevisionID</gl-cor:uniqueID>
</gl-cor:documentInfo>
<gl-cor:entityInformation>
<gl-cor:entityPhoneNumber>
<gl-cor:phoneNumber contextRef="journal_context">779633</gl-cor:phoneNumber>
</gl-cor:entityPhoneNumber>
<gl-cor:entityFaxNumberStructure>
<gl-cor:entityFaxNumbercontextRef="journal_context">1234-56-89</gl-cor:entityFaxNumber>
</gl-cor:entityFaxNumberStructure>
</gl-cor:entityInformation>
而且,我想我的輸出是這個樣子的:
<gl-cor:documentInfo>
<gl-cor:entriesType contextRef="journal_context">DocumentID</gl-cor:entriesType>
<gl-bus:uniqueID contextRef="journal_context">RevisionID</gl-cor:uniqueID>
</gl-cor:documentInfo>
<gl-cor:entityInformation>
<gl-bus:entityPhoneNumber>
<gl-bus:phoneNumber contextRef="journal_context">779633</gl-bus:phoneNumber>
</gl-bus:entityPhoneNumber>
<gl-bus:entityFaxNumberStructure>
<gl-bus:entityFaxNumbercontextRef="journal_context">1234-56-89</gl-bus:entityFaxNumber>
</gl-bus:entityFaxNumberStructure>
</gl-cor:entityInformation>
所有的<gl-cor:entityInformation>
兒童應更換,而不是GL-COR,它應該是GL -總線。是否有可能做到這一點?
我試着創建一個示例xslt,但它沒有工作。該錯誤發生在<gl-bus:phoneNumber>
,因爲我認爲它包含特殊字符?像「 - 」和「:」。
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="gl-cor:entityInformation/gl-cor:entityPhoneNumber/gl-cor:phoneNumber">
<gl-bus:phoneNumber>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</gl-bus:phoneNumber>
</xsl:template>
有人可以幫我解決這個問題嗎?非常感謝。
感謝您的回答。我已經使用你的代碼,當我將xml輸出轉換爲xsl時,錯誤指向了這個部分:gl-bus:{local-name()},我不知道它是什麼意思。 – hannah
@hannah:更新您的問題併發布更多您的輸入XML,因爲您需要設置正確的名稱空間。也給我們你收到的確切的錯誤。 –
哇!我忘了更改xslt中的命名空間。而且,是的,它工作正常。非常感謝。 – hannah