作为计算XML文档之间相似度的一种方法(通常是几种,但在这种情况下是两种),基于标记的相似度计算有几种应用。现在,如何使用XSLT实现这样的方法。
我认为这是这样的:提取标记并为两个文档列出它们。接下来,检查两个列表之间的精确/部分匹配。
在这方面,XSLT是否为比较字符串(标记)提供了任何函数/操作。任何关于这一概念和执行的想法都是受欢迎的。
简单示例:
对于这些XML文档(当然是其中的一部分),
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>而这个,
<books>
<authorname>Ralls, Kim</authorname>
<booktitle>Midnight Rain</booktitle>
<genre>Fantasy</genre>
<cost>5.95</cost>
<date>2000-12-16</date>
<abstract>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</abstract>
</books>这两个文档都有六个元素(标签),其中两种类型都有,标题类似书名,作者有作者名,publish_date有日期。所以,这两者是相似的。(1次精确匹配,3次部分匹配)
发布于 2015-01-21 15:43:25
假设XSLT2.0,以下内容以第一个XML文档作为输入,第二个文档的URL作为参数,然后为第一个文档中的每个元素名称输出第二个文档中包含或包含名称的名称列表:
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="text"/>
<xsl:param name="doc2-url" as="xs:string" select="'test2015012102.xml'"/>
<xsl:variable name="doc2" as="document-node()" select="doc($doc2-url)"/>
<xsl:variable name="doc2-names" as="xs:string*" select="distinct-values($doc2//*/local-name())"/>
<xsl:template match="/">
<xsl:value-of select="for $name in distinct-values(//*/local-name())
return concat($name, ': ', string-join($doc2-names[contains($name, .) or contains(., $name)], ', '))"
separator=" "/>
</xsl:template>
</xsl:stylesheet>因此,对于您的示例,输出是
book: books, booktitle
author: authorname
title: booktitle
genre: genre
price:
publish_date: date
description: https://stackoverflow.com/questions/28068633
复制相似问题