XSLT:选择模板,可变长度为dt_assoc,内部为elem,构建变换为DNS记录格式, [英] XSLT: choose template, variable length dt_assoc inside elem, building transform for DNS records format,

查看:225
本文介绍了XSLT:选择模板,可变长度为dt_assoc,内部为elem,构建变换为DNS记录格式,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XSLT非常新,请原谅我的无知的无知。
另外,我不太流利的Stackoverflow礼节,我希望这不是太长,但这个例子需要一个很好的上下文。
我过去几天一直在努力解决这个问题,学习相当多,但不幸的是,我没有取得任何进展。



我看到[larsh]后重新设计了我的模板( https://stackoverflow.com/users/423105/larsh)在这里回答
[1] 如何打印单个< div>没有关闭它在XSLT



但在我甚至可以得到这么远之前,需要解决这个xsl:选择和属性问题。 (确实,解决方案在我的情况下仍然存在问题,我不知道每种类型的记录有多少,我需要放一个< item type ='xx'> / code>在组中的第一个记录之前打开标签,然后在组中的最终记录之后关闭它。)



我的输入是从Rackspace API作为一个xml文件。
重要部分如下所示:

 < ns2:recordsList totalEntries =5> 
< ns2:record id =A-2542719type =Aname =midsummernightstamps.comdata =198.101.155.141ttl =300updated =2012-10-10T21:34 :52Zcreated =2010-02-17T05:02:16Z//>
< ns2:record id =A-2542719type =Aname =midsummernightstamps.comdata =198.101.155.141ttl =300updated =2012-10-10T21:34 :52Zcreated =2010-02-17T05:02:16Z/>
< ns2:record id =A-2542719type =Aname =midsummernightstamps.comdata =198.101.155.143ttl =300updated =2012-10-10T21:34 :52Zcreated =2010-02-17T05:02:16Z/>
< ns2:record id =NS-3093871type =NSname =midsummernightstamps.comdata =dns1.stabletransit.comttl =300updated =2012-10-10T21 :34:52Zcreated =2010-02-17T05:03:16Z/>
< ns2:record id =NS-3093873type =NSname =midsummernightstamps.comdata =dns2.stabletransit.comttl =300updated =2012-10-10T21 :34:52Zcreated =2010-02-17T05:03:16Z/>
< ns2:record id =CNAME-6051819type =CNAMEname =vh1.midsummernightstamps.comdata =ns1.eiotx.netttl =300updated =2012-10 -10T21:34:52Zcreated =2010-02-17T05:05:09Z/>
< ns2:record id =CNAME-6052005type =CNAMEname =www.midsummernightstamps.comdata =virtual.eiotx.netttl =300updated =2012-10 -10T21:34:52Zcreated =2010-02-17T05:05:09Z/>
< / ns2:recordsList>

输出应该反映以下示例模板,其中每个记录类型是项目中的记录列表在结构下。

 < item key =attributes> 
< dt_assoc>
< item key =domain> example.com< / item>
< item key =records>
< dt_assoc>
< item key =A>
< dt_array>
< item key =0>
< dt_assoc>
< item key =subdomain>< / item>
< item key =ip_address> 123.123.123.2< / item>
< / dt_assoc>
< / item>
< item key =1>
< dt_assoc>
< item key =subdomain> *< / item>
< item key =ip_address> 123.123.123.3< / item>
< / dt_assoc>
< / item>
< item key =2>
< dt_assoc>
< item key =subdomain> www< / item>
< item key =ip_address> 123.123.123.4< / item>
< / dt_assoc>
< / item>
< / dt_array>
< / item>
< item key =CNAME>
< dt_array>
< item key =0>
< dt_assoc>
< item key =subdomain> portal< / item>
< item key =hostname> www.example.com< / item>
< / dt_assoc>
< / item>
< / dt_array>
< / item>等等

(我以为我已经解决了,但OpenSRS API不断抱怨我的XML是我终于意识到,我的模板为每个记录插入了一个新的< item key ={@ type}> ,其中只有一个是孩子dt_array本身每个记录都有一个元素)
经过很多眯眼和胡须拉动,我已经生成了以下XSLT,它根本不生成...
我对这个结果感到神秘我越来越。
(在这里显示两种记录类型的模板和决定。)

 < xsl:stylesheet版本=1.0xmlns:xsl =http://www.w3.org/1999/XSL/Transformxmlns:ns2 =http://docs.rackspacecloud.com/dns/api/v1.0> 
< xsl:output method =xmlindent =yesdoctype-system =OPS.dtd/>
< xsl:template match =/>
< OPS_envelope>
< header>
< version> 0.9< / version>
< / header>
< body>
< data_block>
< dt_assoc>
< xsl:apply-templates />
< / dt_assoc>
< / data_block>
< / body>
< / OPS_envelope>
< / xsl:template>
< xsl:template match =ns2:domain>
< item key =protocol> XCP< / item>
< item key =action> create_dns_zone< / item>
< item key =object> DOMAIN< / item>
< item key =attributes>
< dt_assoc>
< item key =domain>
< xsl:value-of select =// @ name/>
< / item>
< item key =records>
< dt_assoc>
< xsl:apply-templates match =ns2:domain / ns2:recordedList/>
< / dt_assoc>
< / item>
< / dt_assoc>
< / item>
< / xsl:template>
< xsl:template name =recordTypesmatch =ns2:domain / ns2:recordsList / ns2:record>
< p> DEBUG TEMPLATE RECORD TYPES< / p>
< item key ={@ type}>
< xsl:choose>
< xsl:when test =ns2:record [@ type ='A']>
< p>选择A< / p>
< xsl:call-template name =typeAselect =./@ type/>
< / xsl:when>
< xsl:when test =ns2:record [@ type ='CNAME']>
< p>选择CNAME< / p>
< xsl:call-template name =typeCNAMEselect =./@ type/>
< / xsl:when>
< xsl:else> < p> DEBUG OTHERWISE - Nada< / p>
< / xsl:否则>
< / xsl:choose>
< / item>
< / xsl:template>
< xsl:template name =typeAmatch =ns2:record [@ type ='A']>
< p> DEBUG TypeA< / p>
< dt_array>
< item key ={count(previous :: ns2:record [@ type ='A'])}>
< dt_assoc>
< item key =subdomain>
< xsl:value-of select =./@ name/>.</item>
< item key =ip_address>
< xsl:value-of select =./@ data/>
< / item>
< / dt_assoc>
< / item>
< / dt_array>
< / xsl:template>

< xsl:template name =typeCNAME>
< p> DEBUG TypeCNAME< / p>
< dt_array>
< item key ={count(previous :: ns2:record [@ type ='CNAME'])}>
< dt_assoc>
< item key =subdomain>
< xsl:value-of select =./@ name/>.</item>
< item key =hostname>
< xsl:value-of select =./@ data/>
< / item>
<! - < item key =comment>< xsl:value-of select =./@ comment/>< / item> - >
< / dt_assoc>
< / item>
< / dt_array>
< / xsl:template>
<! - 为了清楚起见,删除了其他类型 - >
< / item>
< / dt_array>
< / xsl:template>
< / xsl:stylesheet>

然后,我的示例输入的输出,在哪里可以看到,我的xsl:选择只针对@ type ='A'进行选择,其他所有选项都将被忽略。我已经测试了更改模板的顺序,输入数据记录的顺序等等,但只有A可以在任何地方,但是,它不会打印< item key =xxx > 除了在xsl:otherwise子句中。
这是非常奇怪的,因为计数选择器在typeA模板中工作,但是然后是< item key ={@ type}> 类型为A时不工作...为什么只是A!
我显然是以这种方式在某种程度上在概念上的基础,这并不奇怪,但我一定要看到核心问题真正在哪里。

 <?xml version =1.0?> 
<!DOCTYPE OPS_envelope SYSTEMOPS.dtd>
< OPS_envelope xmlns:ns2 =http://docs.rackspacecloud.com/dns/api/v1.0>
< header>
< version> 0.9< / version>
< / header>
< body>
< data_block>
< dt_assoc>
< item key =protocol> XCP< / item>
< item key =action> create_dns_zone< / item>
< item key =object> DOMAIN< / item>
< item key =attributes>
< dt_assoc>
< item key =domain> midsummernightstamps.com< / item>
< item key =records>
< dt_assoc>
< p> DEBUG TypeA< / p>
< dt_array>
< item key =0>
< dt_assoc>
< item key =subdomain> midsummernightstamps.com< / item>
< item key =ip_address> 198.101.155.141< / item>
< / dt_assoc>
< / item>
< / dt_array>
< p> DEBUG TypeA< / p>
< dt_array>
< item key =1>
< dt_assoc>
< item key =subdomain> midsummernightstamps.com< / item>
< item key =ip_address> 198.101.155.141< / item>
< / dt_assoc>
< / item>
< / dt_array>
< p> DEBUG TypeA< / p>
< dt_array>
< item key =2>
< dt_assoc>
< item key =subdomain> midsummernightstamps.com< / item>
< item key =ip_address> 198.101.155.143< / item>
< / dt_assoc>
< / item>
< / dt_array>
< p> DEBUG TEMPLATE RECORD TYPES< / p>
< item key =NS>
< p> DEBUG OTHERWISE - Nada< / p>
< / item>
< p> DEBUG TEMPLATE RECORD TYPES< / p>
< item key =NS>
< p> DEBUG OTHERWISE - Nada< / p>
< / item>
< p> DEBUG TEMPLATE RECORD TYPES< / p>
< item key =CNAME>
< p> DEBUG OTHERWISE - Nada< / p>
< / item>
< p> DEBUG TEMPLATE RECORD TYPES< / p>
< item key =CNAME>
< p> DEBUG OTHERWISE - Nada< / p>
< / item>
< / dt_assoc>
< / item>
< / dt_assoc>
< / item>
< / dt_assoc>
< / data_block>
< / body>
< / OPS_envelope>


解决方案

你在学习中很好!您应该了解的另一件事是一种名为 Muenchian Grouping 的技术。在你的情况下,它看起来像是通过他们的类型属性组合你的记录元素。在这种情况下,您可以定义一个这样的密钥。

 < xsl:key name =typesmatch =ns2:record use =@ type/> 

然后,您可以选择记录元素在XML中发生特定的类型属性,它们构成组的基础

 < xsl:for-each select =ns2:recordsList / ns2:record [generate-id()= generate-id(key('types',@type)[1]) ]> 

然后,要构建组(即选择组中的所有元素),您可以使用函数本身

 < item key ={@类型}> 
< xsl:apply-templates select =key('types',@type)/>
< / item>

您还可以考虑组合模板,以避免代码重复过多。



尝试这个XSLT:

 < xsl:stylesheet version =1.0xmlns:xsl =http://www.w3.org/1999/XSL/Transformxmlns:ns2 =http://docs.rackspacecloud.com/dns/api/v1.0> 
< xsl:output method =xmlindent =yesdoctype-system =OPS.dtd/>

< xsl:key name =typesmatch =ns2:recorduse =@ type/>

< xsl:template match =/>
< OPS_envelope>
< header>
< version> 0.9< / version>
< / header>
< body>
< data_block>
< dt_assoc>
< xsl:apply-templates />
< / dt_assoc>
< / data_block>
< / body>
< / OPS_envelope>
< / xsl:template>

< xsl:template match =ns2:domain>
< item key =protocol> XCP< / item>
< item key =action> create_dns_zone< / item>
< item key =object> DOMAIN< / item>
< item key =attributes>
< dt_assoc>
< item key =domain>
< xsl:value-of select =@ name/>
< / item>
< item key =records>
< dt_assoc>
< xsl:for-each select =ns2:recordsList / ns2:record [generate-id()= generate-id(key('types',@type)[1])]>
< item key ={@ type}>
< xsl:apply-templates select =key('types',@type)/>
< / item>
< / xsl:for-each>
< / dt_assoc>
< / item>
< / dt_assoc>
< / item>
< / xsl:template>

< xsl:template match =ns2:record>
< dt_array>
< item key ={position() - 1}>
< dt_assoc>
< item key =subdomain>
< xsl:value-of select =./@ name/>
< xsl:text>。< / xsl:text>
< / item>
< xsl:choose>
< xsl:when test =@ type ='A'>
< item key =ip_address>
< xsl:value-of select =@ data/>
< / item>
< / xsl:when>
< xsl:else>
< item key =hostname>
< xsl:value-of select =@ data/>
< / item>
< / xsl:否则>
< / xsl:choose>
< / dt_assoc>
< / item>
< / dt_array>
< / xsl:template>
< / xsl:stylesheet>

请注意,这只假设只有一个在你的XML中如果您有多个域名,并且希望为每个域分组记录,则应该将密钥更改为

 < xsl: key name =typesmatch =ns2:recorduse =concat(@type,../../@name)/> 

请确保您相应地调整所有用途的使用。


I am very very new at XSLT, please forgive my oblivious cluelessness. Also, I am not fluent on Stackoverflow etiquette, I hope this is not excessively long, but the example requires a good bit of context. I've been trying to solve this problem for the past few days, learning quite a lot along the way, but unfortunately, I'm not making any more progress.

I redesigned my templates after seeing [larsh] (https://stackoverflow.com/users/423105/larsh) answer here [1] How can I print a single <div> without closing it in XSLT

but before I can even get that far, need to solve this "xsl:choose" and attributes problem. (Indeed that solution still presents problems in my case, that I don't know how many records of each type there are. I'll need to put an <item type='xx'> open tag before the first record in a group and then close it after the final in the group.)

My input is a DNS record exported from Rackspace API as an xml file. The important part looks like this:

<ns2:recordsList totalEntries="5">
    <ns2:record id="A-2542719" type="A" name="midsummernightstamps.com" data="198.101.155.141" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:02:16Z" />
    <ns2:record id="A-2542719" type="A" name="midsummernightstamps.com" data="198.101.155.141" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:02:16Z" />
    <ns2:record id="A-2542719" type="A" name="midsummernightstamps.com" data="198.101.155.143" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:02:16Z" />       
    <ns2:record id="NS-3093871" type="NS" name="midsummernightstamps.com" data="dns1.stabletransit.com" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:03:16Z" />
    <ns2:record id="NS-3093873" type="NS" name="midsummernightstamps.com" data="dns2.stabletransit.com" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:03:16Z" />
    <ns2:record id="CNAME-6051819" type="CNAME" name="vh1.midsummernightstamps.com" data="ns1.eiotx.net" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:05:09Z" />
    <ns2:record id="CNAME-6052005" type="CNAME" name="www.midsummernightstamps.com" data="virtual.eiotx.net" ttl="300" updated="2012-10-10T21:34:52Z" created="2010-02-17T05:05:09Z" />
</ns2:recordsList>

The output should reflect the following example template, where each record type is a list of records within the item under the structure.

<item key="attributes">
      <dt_assoc>
        <item key="domain">example.com</item>
        <item key="records">
          <dt_assoc>
            <item key="A">
              <dt_array>
                <item key="0">
                  <dt_assoc>
                    <item key="subdomain"></item>
                    <item key="ip_address">123.123.123.2</item>
                  </dt_assoc>
                </item>
                <item key="1">
                  <dt_assoc>
                    <item key="subdomain">*</item>
                    <item key="ip_address">123.123.123.3</item>
                  </dt_assoc>
                </item>
                <item key="2">
                  <dt_assoc>
                    <item key="subdomain">www</item>
                    <item key="ip_address">123.123.123.4</item>
                  </dt_assoc>
                </item>
              </dt_array>
            </item>
            <item key="CNAME">
              <dt_array>
                <item key="0">
                  <dt_assoc>
                    <item key="subdomain">portal</item>
                    <item key="hostname">www.example.com</item>
                  </dt_assoc>
                </item>
              </dt_array>
            </item> etc.

(I thought I had it worked out, but the OpenSRS API kept complaining that my XML was invalid. I finally realized that my templates inserted a new <item key="{@type}"> for every record, where in fact there is only one which is the child dt_array which itself has one element per record.) After much squinting and beard pulling, I have produced the following XSLT, which is not producing at all... I am mystified as to the results I'm getting. (Showing the templates and decision for just two of the record types here.)

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns2="http://docs.rackspacecloud.com/dns/api/v1.0">
  <xsl:output method="xml" indent="yes" doctype-system="OPS.dtd" />
  <xsl:template match="/">
    <OPS_envelope>
      <header>
        <version>0.9</version>
      </header>
      <body>
        <data_block>
          <dt_assoc>
            <xsl:apply-templates />
          </dt_assoc>
        </data_block>
      </body>
    </OPS_envelope>
  </xsl:template>
  <xsl:template match="ns2:domain">
    <item key="protocol">XCP</item>
    <item key="action">create_dns_zone</item>
    <item key="object">DOMAIN</item>
    <item key="attributes">
      <dt_assoc>
        <item key="domain">
          <xsl:value-of select="//@name" />
        </item>
        <item key="records">
          <dt_assoc>
            <xsl:apply-templates match="ns2:domain/ns2:recordsList" />
          </dt_assoc>
        </item>
      </dt_assoc>
    </item>
  </xsl:template>
  <xsl:template name="recordTypes" match="ns2:domain/ns2:recordsList/ns2:record">
    <p>DEBUG TEMPLATE RECORD TYPES</p>
    <item key="{@type}">
      <xsl:choose>
       <xsl:when test="ns2:record[@type='A']">
          <p>Choose A</p>
          <xsl:call-template name="typeA" select="./@type" />
        </xsl:when>
        <xsl:when test="ns2:record[@type='CNAME']">
          <p>Choose CNAME</p>
          <xsl:call-template name="typeCNAME" select="./@type" />
        </xsl:when>        
        <xsl:otherwise> <p>DEBUG OTHERWISE - Nada</p>
        </xsl:otherwise>
      </xsl:choose>
    </item>
  </xsl:template>
  <xsl:template name="typeA" match="ns2:record[@type='A']">
    <p>DEBUG TypeA</p>
    <dt_array>
      <item key="{count(preceding::ns2:record[@type='A'])}">
        <dt_assoc>
          <item key="subdomain">
          <xsl:value-of select="./@name" />.</item>
          <item key="ip_address">
            <xsl:value-of select="./@data" />
          </item>
        </dt_assoc>
      </item>
    </dt_array>
  </xsl:template>

  <xsl:template name="typeCNAME">
    <p>DEBUG TypeCNAME</p>
    <dt_array>
      <item key="{count(preceding::ns2:record[@type='CNAME'])}">
        <dt_assoc>
          <item key="subdomain">
          <xsl:value-of select="./@name" />.</item>
          <item key="hostname">
            <xsl:value-of select="./@data" />
          </item>
          <!--<item key="comment"><xsl:value-of select="./@comment" /></item> -->
        </dt_assoc>
      </item>
    </dt_array>
  </xsl:template>
<!-- additional types removed for clarity -->
      </item>
    </dt_array>
  </xsl:template>
</xsl:stylesheet>

And, following, the output against my sample input, where it will be seen, that my xsl:choose is only selected against "@type='A'", and all the others are ignored. I've tested changing the order of the templates, the order of the input data records, etc, but only the "A" gets anywhere, BUT, it will not print the <item key="xxx"> except in the 'xsl:otherwise' clause. This is very strange, since the count selector is working in the "typeA" template, but then the <item key="{@type}"> does not work when the type is "A"... Why just the "A"!?! I'm obviously way off base here somehow conceptually, which is no surprise, but I'd sure like to see where the core problem really is.

    <?xml version="1.0"?>
<!DOCTYPE OPS_envelope SYSTEM "OPS.dtd">
<OPS_envelope xmlns:ns2="http://docs.rackspacecloud.com/dns/api/v1.0">
  <header>
    <version>0.9</version>
  </header>
  <body>
    <data_block>
      <dt_assoc>
        <item key="protocol">XCP</item>
        <item key="action">create_dns_zone</item>
        <item key="object">DOMAIN</item>
        <item key="attributes">
          <dt_assoc>
            <item key="domain">midsummernightstamps.com</item>
            <item key="records">
              <dt_assoc>
                <p>DEBUG TypeA</p>
                <dt_array>
                  <item key="0">
                    <dt_assoc>
                      <item key="subdomain">midsummernightstamps.com.</item>
                      <item key="ip_address">198.101.155.141</item>
                    </dt_assoc>
                  </item>
                </dt_array>
                <p>DEBUG TypeA</p>
                <dt_array>
                  <item key="1">
                    <dt_assoc>
                      <item key="subdomain">midsummernightstamps.com.</item>
                      <item key="ip_address">198.101.155.141</item>
                    </dt_assoc>
                  </item>
                </dt_array>
                <p>DEBUG TypeA</p>
                <dt_array>
                  <item key="2">
                    <dt_assoc>
                      <item key="subdomain">midsummernightstamps.com.</item>
                      <item key="ip_address">198.101.155.143</item>
                    </dt_assoc>
                  </item>
                </dt_array>
                <p>DEBUG TEMPLATE RECORD TYPES</p>
                <item key="NS">
                  <p>DEBUG OTHERWISE - Nada</p>
                </item>
                <p>DEBUG TEMPLATE RECORD TYPES</p>
                <item key="NS">
                  <p>DEBUG OTHERWISE - Nada</p>
                </item>
                <p>DEBUG TEMPLATE RECORD TYPES</p>
                <item key="CNAME">
                  <p>DEBUG OTHERWISE - Nada</p>
                </item>
                <p>DEBUG TEMPLATE RECORD TYPES</p>
                <item key="CNAME">
                  <p>DEBUG OTHERWISE - Nada</p>
                </item>
              </dt_assoc>
            </item>
          </dt_assoc>
        </item>
      </dt_assoc>
    </data_block>
  </body>
</OPS_envelope>

解决方案

It is good you are learning on the way! The next thing you should probably learn about is a technique called Muenchian Grouping. In your case, it looks like you "group" your record elements by their type attribute. In this case, you define a key like so

 <xsl:key name="types" match="ns2:record" use="@type" />

You then start off by selecting the record element which has the fist occurrence of a particular type attribute in the XML, which forms the basis of the group

<xsl:for-each select="ns2:recordsList/ns2:record[generate-id() = generate-id(key('types', @type)[1])]">

Then, to build the group (i.e. to select all the elements in the group), you can just use the key function itself

<item key="{@type}">
    <xsl:apply-templates select="key('types', @type)" />
</item>

You might also consider combining your templates, to avoid too much code repetition.

Try this XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns2="http://docs.rackspacecloud.com/dns/api/v1.0">
  <xsl:output method="xml" indent="yes" doctype-system="OPS.dtd" />

  <xsl:key name="types" match="ns2:record" use="@type" />

  <xsl:template match="/">
    <OPS_envelope>
      <header>
        <version>0.9</version>
      </header>
      <body>
        <data_block>
          <dt_assoc>
            <xsl:apply-templates />
          </dt_assoc>
        </data_block>
      </body>
    </OPS_envelope>
  </xsl:template>

  <xsl:template match="ns2:domain">
    <item key="protocol">XCP</item>
    <item key="action">create_dns_zone</item>
    <item key="object">DOMAIN</item>
    <item key="attributes">
      <dt_assoc>
        <item key="domain">
          <xsl:value-of select="@name" />
        </item>
        <item key="records">
          <dt_assoc>
            <xsl:for-each select="ns2:recordsList/ns2:record[generate-id() = generate-id(key('types', @type)[1])]">
                <item key="{@type}">
                    <xsl:apply-templates select="key('types', @type)" />
                </item>
            </xsl:for-each>
          </dt_assoc>
        </item>
      </dt_assoc>
    </item>
  </xsl:template>

  <xsl:template match="ns2:record">
    <dt_array>
      <item key="{position() - 1}">
        <dt_assoc>
          <item key="subdomain">
            <xsl:value-of select="./@name" />
              <xsl:text>.</xsl:text>
          </item>
          <xsl:choose>
              <xsl:when test="@type='A'">
                  <item key="ip_address">
                    <xsl:value-of select="@data" />
                  </item>
              </xsl:when>
              <xsl:otherwise>
                  <item key="hostname">
                    <xsl:value-of select="@data" />
                  </item>
              </xsl:otherwise>
          </xsl:choose>
        </dt_assoc>
      </item>
    </dt_array>
  </xsl:template>
</xsl:stylesheet>

Note that this assumes only one domain element in your XML. If you have multiple domains, and want to group records per domain, you should change your key to this instead

<xsl:key name="types" match="ns2:record" use="concat(@type, ../../@name)" />

Make sure you adjust all the uses of the key accordingly too.

这篇关于XSLT:选择模板,可变长度为dt_assoc,内部为elem,构建变换为DNS记录格式,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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