[英]How to make a linkTag from the specific Tag in a XML file using XSLT
我想更改以下 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”到“Explanation”的鏈接。 所有 linkSource 和 linkDestinition 都在已經定義的 XML 文件中。
誰能幫幫我嗎?
(對不起,我的英語不是很好,但我希望我能夠很好地解釋這個問題)。
請嘗試以下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>
Output 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.