我想更改以下 XML 中的具體標簽。標簽<linkSource>應轉換為 <fo:basic-link internal-destination="boothId">,標簽 <linkDestination>應轉換為<fo:block id="boothId">.
<root>
<directCompNotes>
<paragraph>Go to:</paragraph>
<bullet-list>
<item>
<paragraph>
<linkSource>
Booth
</linkSource>
</paragraph>
</item>
<item>
<paragraph>
WithoutLinkSource
</paragraph>
</item>
</bullet-list>
</directCompNotes>
<directComp>
<paragraph>
<linkDestination>
Explainition
</linkDestination>
</paragraph>
</directComp>
</root>
這就是我試圖做的:
<xsl:template match="root">
<xsl:for-each select="directCompNotes/bullet-list/item/paragraph/linkSource">
<fo:basic-link internal-destination="boothId">
<xsl:value-of select="."/>
</fo:basic-link>
</xsl:for-each>
</xsl:template>
目標是我應該能夠創建從“Booth”到“Explanition”的鏈接。所有的 linkSource 和 linkDestinition 都在已定義的 XML 檔案中。
任何人都可以幫助我嗎?
(對不起,我的英語不是很好,但我希望我能夠很好地解釋這個問題)。
uj5u.com熱心網友回復:
請嘗試以下 XSLT。
輸入 XML
<?xml version="1.0"?>
<root>
<directCompNotes>
<paragraph>Go to:</paragraph>
<bullet-list>
<item>
<paragraph>
<linkSource>Booth</linkSource>
</paragraph>
</item>
<item>
<paragraph>WithoutLinkSource</paragraph>
</item>
</bullet-list>
</directCompNotes>
<directComp>
<paragraph>
<linkDestination>Explainition</linkDestination>
</paragraph>
</directComp>
</root>
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:apply-templates/>
</fo:root>
</xsl:template>
<xsl:template match="linkSource">
<fo:basic-link internal-destination="boothId">
<xsl:value-of select="."/>
</fo:basic-link>
</xsl:template>
<xsl:template match="linkDestination">
<fo:block id="boothId">
<xsl:value-of select="."/>
</fo:block>
</xsl:template>
</xsl:stylesheet>
輸出 XML
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<directCompNotes>
<paragraph>Go to:</paragraph>
<bullet-list>
<item>
<paragraph>
<fo:basic-link internal-destination="boothId">Booth</fo:basic-link>
</paragraph>
</item>
<item>
<paragraph>WithoutLinkSource</paragraph>
</item>
</bullet-list>
</directCompNotes>
<directComp>
<paragraph>
<fo:block id="boothId">Explainition</fo:block>
</paragraph>
</directComp>
</fo:root>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/437610.html
