XSLT无法将DITA转换为新类型 [英] XSLT fails to transform DITA into new type

查看:79
本文介绍了XSLT无法将DITA转换为新类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xml如下:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE concept SYSTEM "aimlDomain.dtd">
<?xml-stylesheet type="text/xsl" href="aimlTest.xsl"?>
<concept>
<category>
   <pattern>_ TOPIC ELEMENT ATTRIBUTE</pattern>
   <template><srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai> 
   </template>
</category> 
<category>
   <pattern>TOPIC ELEMENT ATTRIBUTE _</pattern>
   <template><srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai> 
   </template>
</category>
</concept>

元素类别是我添加的带有元素专门化的新域,它是从外来元素专门化的.我想将文件转换为新的transformtype的aiml. 预期的输出应该是这样的:

The element category is the new domain I add with element specialization, which is specialized from foreign element.I want to transform the file into aiml, a new transformtype. The expected output shoud be like this:

`   <?xml version="1.0" encoding="utf-8"?>
    <category>
      <pattern>_ TOPIC ELEMENT ATTRIBUTE</pattern>
      <template><srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai> 
      </template>
    </category>`

但是文件中除了声明以外什么都没有.实际输出如下:

But there is nothing in the file except the declaratinon.The actual output is as following:

<?xml version="1.0" encoding="UTF-8"?>

这是我的aimlTest.xsl:

Here is my aimlTest.xsl:

  <xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="*[contains(@class, ' topic/topic topic/concept ')]">
    <xsl:for-each select="*[contains(@class, ' topic/foreign category-d/category 
    ')]">
    <xsl:copy-of select="."/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

我想知道如何选择期望的内容.

I want to know how to select the expected content.

推荐答案

有很多无关紧要的因素使事情变得更加复杂.一种是在@class属性而不是元素名称上进行匹配.所以我做了一个简化版,见下文.

There are a lot of extraneous factors that are making this more complicated. One is matching on the @class attribute instead of element names. So I did a simplified version, see below.

这是我使用的输入DITA文件(我删除了您的DTD和XSLT PI,因为在此示例中不需要它们):

Here is the input DITA file I used (I removed your DTD and XSLT PI because I didn't need them for this example):

<?xml version="1.0" encoding="utf-8"?>
<concept>
  <category>
    <pattern>_ TOPIC ELEMENT ATTRIBUTE</pattern>
    <template>
      <srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai>
    </template>
  </category>
  <category>
    <pattern>TOPIC ELEMENT ATTRIBUTE _</pattern>
    <template>
      <srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai>
    </template>
  </category>
</concept>

这是我使用的XSLT,仅与元素名称匹配:

Here is the XSLT I used, matching only on element names:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="concept">
    <root>
      <xsl:for-each select="category">
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </root>
  </xsl:template>
</xsl:stylesheet>

我在XSLT中添加了一个根元素(称为<root>,可以是任何名称),因此输出将是正确的XML.

I added a root element (called <root>, could be any name) to the XSLT so the output would be proper XML.

这是输出:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <category>
    <pattern>_ TOPIC ELEMENT ATTRIBUTE</pattern>
    <template>
      <srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai>
    </template>
  </category>
  <category>
    <pattern>TOPIC ELEMENT ATTRIBUTE _</pattern>
    <template>
      <srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai>
    </template>
  </category>
</root>

如果需要,可以将其重构为使用@class属性匹配,但是我怀疑您不需要它.如果确实需要它,请首先确保DTD正确添加了类属性.在DITA DTD中,类属性是默认"的,这意味着它们将包含在每个XML实例中,即使它们不是字面意义上的XML(有关语法,请参见DITA DTD).出于发布目的,DITA OT在DITA XML文件上运行初步过程,该过程会在运行XSLT之前提取所有默认的@class属性.然后,XML看起来像这样:

If you want, you can refactor it back to use the @class attribute matching, but I suspect you don't need it. If you do need it, first make sure your DTD adds the class attributes properly. In the DITA DTDs, the class attributes are "defaulted", which means they are included in every XML instance, even if they are not literally in the XML (see the DITA DTDs for syntax). For publishing purposes, the DITA OT runs a preliminary process on the DITA XML files that pulls in all the defaulted @class attributes before the XSLT is run. Then the XML looks something like this:

<concept class=" topic/concept ">
  <category class=" topic/foreign category-d/category ">
    <pattern class=" etc ">_ TOPIC ELEMENT ATTRIBUTE</pattern>
    <template class=" etc ">
      <srai>REQUIRED TOPIC AND MAP ELEMENT ATTRIBUTES</srai>
    </template>
  </category>
[...]

然后您的原始XSLT可以在类属性上匹配.在这些@class属性上进行匹配有DITA的充分理由,但是您可能不需要这样做,而您试图通过这样做来增加复杂性.

And then your original XSLT could match on the class attributes. There's a good DITA reason for matching on these @class attributes but you might not need to do it, and you are adding complication by trying to do it.

这篇关于XSLT无法将DITA转换为新类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆