我正在嘗試創建一個xsl文件,它將通過一個xml文件並僅處理以特定字符集開頭的標記。我應該提到,我對xsl文件相當陌生,所以這可能很容易完成,但我只是不知道如何。XSL如何選擇以特定字符集開頭的每個選項卡?
我的XML文件看起來與此類似:
<generic_etd>
<associated_tags>
<master>
<dc.contributor>contributor</dc.contributor>
</master>
<related>
<dc.contributor.role>contributor role</dc.contributor.role>
</related>
</associated_tags>
<associated_tags>
<master>
<dc.contributor>sponsor</dc.contributor>
</master>
<related>
<dc.contributor.role>sponsor role</dc.contributor.role>
</related>
</associated_tags>
<dc.creator>gradstudent2</dc.creator>
<dc.date>2014-02-11</dc.date>
<dc.description>description</dc.description>
<thesis.degree.discipline>Business Administration</thesis.degree.discipline>
<generic_etd>
我希望我的XSL文件到開頭只有過程變量「DC。」
這是我想出迄今XSL文件:
<xsl:template match="*">
<xsl:choose>
<!-- Process the tags we are interested in -->
<xsl:when test="contains(name(),'dc.')">
<xsl:variable name="newtag" select="concat('dc:',substring-after(name(),'.'))"/>
<xsl:choose>
<xsl:when test="contains($newtag, '.')">
<xsl:element name="{substring-before($newtag,'.')}">
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{$newtag}">
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
但是它產生的文件丟失dc.contributor並從輸出dc.contributor.role。其實,我想在這個例子中排除dc.contributor.role,但是我會在另一個我正在處理的文件中需要它。
我的問題是我去哪裏錯了?
謝謝。
嚴正....你是否試圖將dc。如果是這樣,你也會想要在你的替代xsl:元素上聲明這一點。如果沒有,則不能在元素名稱中使用冒號;這是保留用作名稱空間前綴。 – keshlam
是的,我正在命名它。我只顯示了我遇到問題的部分代碼。 – user5013