0
我在這裏有一些DITA內容。xslt 2.0檢查元素是否在同一個文件夾中的許多其他元素中引用
DITA映射是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN"
"../dtd/technicalContent/dtd/map.dtd">
<map id="e7de5b">
<title/>
<topicmeta>
<othermeta name="title" content="File Loader Guide for SAP HANA"/>
<othermeta name="status" content="Authoring:closed"/>
</topicmeta>
<topicref href="9df1475208c.xml"/>
<mapref href="ec152470.ditamap"/>
</map>
在此文件夾,我知道,這是主要的地圖,因爲它引用的唯一其他DITA地圖(<mapref href="ec152470.ditamap"/>
)。基本上,一個文件夾的主要地圖是沒有被該文件夾中的任何其他地圖引用的地圖(可以有任意數量的地圖)。
我有一個包含所有地圖列表,像這樣的文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<maps>
<map path="Path\ToTheMap" name="e7de5b.ditamap" />
<map path="Path\ToTheMap" name="ec152470.ditamap" />
</maps>
什麼是最好的方式來檢查,如果一個地圖文件夾中的主圖,我。即檢查它是否被該文件夾中的其他地圖引用?
到目前爲止我有:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="fo fn xs">
<xsl:output method="xml" encoding="utf-8" standalone="yes"/>
<xsl:template match="/">
<docMaps>
<xsl:apply-templates/>
</docMaps>
</xsl:template>
<xsl:template match="maps">
<xsl:for-each-group select="map" group-by="@path">
<xsl:choose>
<xsl:when test="count(current-group()) = 1">
<mapdoc path="{current-grouping-key()}" name="{@name}"/>
</xsl:when>
<xsl:otherwise>
<!-- check -->
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
如果只有一個文件夾中的地圖,這是微不足道的。但在另一種情況下...我試過 - 每個循環,但我不能弄清楚。
任何幫助高度讚賞!
感謝您的答覆!在接下來的日子裏,我會努力工作,而不是看看我的代碼,看看它是否有用。 – user3813234