生成丢失的XML [英] Generate missing XML

查看:134
本文介绍了生成丢失的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用XSL文件来格式化文档,以便在我的网站上显示.内容块具有标题,并包含HTML内容.引用部分始终显示在呈现的文档的底部(无论其在XML文件中的位置如何).

<?xml version ="1.0"?>
< mydoc>
   < content title =简介">
      ...
   </content>
  <引用>
     ...
   </references>
</mydoc>

在XSL中,我想为文档创建内容.我设法获得了目录中列出的内容部分.但是我发现自己在复制大量XSL,只是为了将引用部分添加到内容中.

有没有一种方法可以按照以下方式进行操作?

< xsl:变量名="contents-listing">
  串联
      ??获取内容节点"/mydoc/content"的列表??
  与
      < content title =参考">
         <引用>
           ...
         </references>
      </content>
</xsl:variable>

这样我就可以:

< xsl:for-each select ="$ contents_listing">
   <!-单击一个项目会转到相应的命名锚->
   < a>
      < xsl:attribute name ="href">
         < xsl:value-of select ="concat("#ref,position())"/>
      </xsl:attribute>
      < xsl:value-of select ="@ title"/>
  </a>
</xsl:for-each>

以及:

< xsl:for-each select ="$ contents-listing">
   <!-命名后的锚点表示单击该链接的位置->
   < a>
      < xsl:attribute name ="name">
        < xsl:value-of select ="concat(" ref,position())"/>
      </xsl:attribute>
     < xsl:apply-templates/>
   </a>
</xsl:for-each>

非常感谢,
Lea Hayes

解决方案

contents_listing">
 <!-单击一个项目将转到相应的已命名锚点->
  < a>
    < ; xsl:attribute name ="href">
      < xsl:value-of select ="concat("#ref,position())" />
   </xsl:attribute>
    < xsl:value-of select ="@ title"/>
 </a>
</xsl:for-each>

以及:

< xsl:for-each select ="

contents-listing>
 <!-命名的锚点指示要单击的位置---->
 < a>
   < xsl:属性名称=名称">
      < xsl:value-of select ="concat(' 'ref'',position())"/>
   </xsl:attribute>
     < xsl:apply-templates/>
   </a>
</xsl:for-each>

非常感谢,
Lea Hayes


在XSLT中很容易2,但是如果像我们大多数依赖Microsoft工具的人一样使用XSLT 1,请避免使用重复的xsl代码.

在这种情况下,我有时会采用一种变通办法,看起来像这样:

< mydoc>
   < content title =简介">
        
             < xsl:call-template name ="EvaluateContent">
         < xsl:with-param name =上下文">内容</xsl:with-param>
     </xsl:call-template>
       
   </content>
  <引用>
       
             < xsl:call-template name ="EvaluateContent">
         < xsl:with-param name ="Context">参考文献</xsl:with-param>
     </xsl:call-template>
       
   </references>
</mydoc>
< xsl:template name ="EvaluateContent">

     < xsl:param name ="Context"/>
   
    < xsl:for-each select ="/mydoc/content">
    
        < xsl:choose>
           
            < xsl:when test ="


Hi,

I am using an XSL file to format a document for display on my website. A content block has a title, and contains HTML content. The references section always appears at the bottom of the rendered document (regardless of its location within the XML file).

<?xml version="1.0"?>
<mydoc>
   <content title="Introduction">
      ...
   </content>
   <references>
      ...
   </references>
</mydoc>

In the XSL I want to create a contents for the document. I have managed to get the content sections listed in the contents. But I find myself duplicating a large chunk of XSL just to add the references section to the contents.

Is there a way to do something along the lines of the following?

<xsl:variable name="contents-listing">
   concatenate
      ?? Get list of content nodes "/mydoc/content" ??
   with
      <content title="References">
         <references>
            ...
         </references>
      </content>
</xsl:variable>

so that I can:

<xsl:for-each select="$contents_listing">
   <!-- Clicking an item goes to the corresponding named anchor -->
   <a>
      <xsl:attribute name="href">
         <xsl:value-of select="concat(''#ref'', position())" />
      </xsl:attribute>
      <xsl:value-of select="@title" />
   </a>
</xsl:for-each>

and also:

<xsl:for-each select="$contents-listing">
   <!-- Named anchor indicates where to click goes to -->
   <a>
      <xsl:attribute name="name">
         <xsl:value-of select="concat(''ref'', position())" />
      </xsl:attribute>
      <xsl:apply-templates />
   </a>
</xsl:for-each>

Many thanks,
Lea Hayes

解决方案

contents_listing">
   <!-- Clicking an item goes to the corresponding named anchor -->
   <a>
      <xsl:attribute name="href">
         <xsl:value-of select="concat(''#ref'', position())" />
      </xsl:attribute>
      <xsl:value-of select="@title" />
   </a>
</xsl:for-each>

and also:

<xsl:for-each select="


contents-listing">
   <!-- Named anchor indicates where to click goes to -->
   <a>
      <xsl:attribute name="name">
         <xsl:value-of select="concat(''ref'', position())" />
      </xsl:attribute>
      <xsl:apply-templates />
   </a>
</xsl:for-each>

Many thanks,
Lea Hayes


It''s probably easy in XSLT 2, but if you''re using XSLT 1 like most of us who are relying on Microsoft tools, avoiding duplicated xsl code ist hard.

Using a workaround pattern I''ve sometimes applied in such cases it would look like this:

<mydoc>
   <content title="Introduction">
        
              <xsl:call-template name="EvaluateContent">
          <xsl:with-param name="Context">Contents</xsl:with-param>
     </xsl:call-template>
        
   </content>
   <references>
        
              <xsl:call-template name="EvaluateContent">
          <xsl:with-param name="Context">References</xsl:with-param>
     </xsl:call-template>
        
   </references>
</mydoc>

<xsl:template name="EvaluateContent">

     <xsl:param name="Context" />
    
     <xsl:for-each select="/mydoc/content">
    
          <xsl:choose>
              
               <xsl:when test="


这篇关于生成丢失的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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