【问题标题】:Show page title for all pages when we print XSLT Report using XML当我们使用 XML 打印 XSLT 报告时显示所有页面的页面标题
【发布时间】:2015-03-12 22:49:11
【问题描述】:

我想通过在所有页面中将 PatientID 作为标题或标题来打印报告,以便在我们打印时它会在所有页面中打印页面标题 我不确定如何编写 XSLT 以在所有页面中显示标题

下面是我的代码

XSLT 代码

 <?xml version="1.0" encoding="ISO-8859-1"?>

    <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL /Transform">
    <xsl:output method="html" version='1.0' indent ='yes' omit-xml-declaration="yes"/>
    <xsl:template match="/">

        <html>

     <STYLE TYPE="text/css">
     p     { line-height: "1"}
     br     { line-height: "1pt"}

     </STYLE>

     <body>

  <table >
      <xsl:for-each select="Report/PatDetails">

    <tr>

    <td align = "left" width = "250" height="50"  style="text-align: justify">
        <font name="Book Antiqua"  size="5.0"><B>

                    <xsl:call-template 
                name="substring-before-last">
                <xsl:with-param name="input" select="Value"/>
                <xsl:with-param name="marker" select="'@'" />
                </xsl:call-template>
</B>
        </font>
    </td>

      <td align = "left" width = "600" height="30">
        <font name="Book Antiqua"  size="5.0">

                <xsl:call-template 
                name="substring-after-last">
                <xsl:with-param name="input" select="Value"/>
                <xsl:with-param name="marker" select="'@'" />
                </xsl:call-template>
        </font>
      </td>

    </tr>

    </xsl:for-each>
    </table></body>

        </html>
    </xsl:template>


    <xsl:template name="string-replace">
        <xsl:param name="arg"/>
        <xsl:param name="toReplace"/>
        <xsl:choose>
            <xsl:when test="contains($arg, $toReplace)">
                <xsl:variable name="prefix" select="substring-before($arg, $toReplace)"/>
                <xsl:variable name="postfix" select="substring($arg, string- length($prefix)+string-length($toReplace)+1)"/>
                <xsl:value-of select="$prefix"/>
                <xsl:text disable-output-escaping="yes">&lt;br/&      gt;</xsl:text>
                <xsl:call-template name="string-replace">
                    <xsl:with-param name="arg" select="$postfix"/>
                    <xsl:with-param name="toReplace" select="$toReplace"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$arg"/>
            </xsl:otherwise>
        </xsl:choose>
     </xsl:template>


     <xsl:template name="substring-after-last">
     <xsl:param name="input" />
     <xsl:param name="marker" />

     <xsl:choose>
      <xsl:when test="contains($input,$marker)">
      <xsl:call-template name="substring-after-last">
      <xsl:with-param name="input" 
          select="substring-after($input,$marker)" />
      <xsl:with-param name="marker" select="$marker" />
      </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
     <xsl:value-of select="$input" />
     </xsl:otherwise>
     </xsl:choose>

     </xsl:template>


     <xsl:template name="substring-before-last">
     <xsl:param name="input" />
     <xsl:param name="marker" />

     <xsl:choose>
     <xsl:when test="contains($input,$marker)">
      <xsl:call-template name="substring-before-last">
      <xsl:with-param name="input" 
          select="substring-before($input,$marker)" />
      <xsl:with-param name="marker" select="$marker" />
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$input" />
    </xsl:otherwise>
    </xsl:choose>

    </xsl:template>

    </xsl:transform>

下面是我的 XML 代码

<?xml version="1.0"?>
<?xml-stylesheet type= 'text/xsl' href = 'HNP.xsl'?>

<Report>
<PatDetails>
<Value>Patient Id:@9999</Value></PatDetails>

<Impression>
<Value>1. @Test1</Value></Impression>

<Impression>
<Value>2. @Test2</Value></Impression>

<Impression>
<Value>3. @Test3</Value></Impression>

<Impression>
<Value>4. @Test4</Value></Impression>

<Impression>
<Value>5. @Test5</Value></Impression>

<Impression>
<Value>6. @Test6</Value></Impression>

<Impression>
<Value>7. @Test7</Value></Impression>

<Impression>
<Value>8. @Test8</Value></Impression>

<Impression>
<Value>1. @Test1</Value></Impression>

<Impression>
<Value>2. @Test2</Value></Impression>

<Impression>
<Value>3. @Test3</Value></Impression>

<Impression>
<Value>4. @Test4</Value></Impression>

<Impression>
<Value>5. @Test5</Value></Impression>

<Impression>
<Value>6. @Test6</Value></Impression>

<Impression>
<Value>7. @Test7</Value></Impression>

<Impression>
<Value>8. @Test8</Value></Impression>


<Impression>
<Value>1. @Test1</Value></Impression>

<Impression>
<Value>2. @Test2</Value></Impression>

<Impression>
<Value>3. @Test3</Value></Impression>

<Impression>
<Value>4. @Test4</Value></Impression>

<Impression>
<Value>5. @Test5</Value></Impression>

<Impression>
<Value>6. @Test6</Value></Impression>

<Impression>
<Value>7. @Test7</Value></Impression>

<Impression>
<Value>8. @Test8</Value></Impression>

</Report>

【问题讨论】:

    标签: xml xslt header report title


    【解决方案1】:

    我不确定您到底想做什么,但似乎您需要阅读 XSLT。首先,您需要记住,所有内容都需要添加到 HTML 标记中,以便以您想要的样式或位置显示。其次,您需要知道在引用特定 XML 标记时指向何处。这是您重写 XSLT 的一种天真的尝试,将其放入新的 xsl:stylesheet 标记中,然后按照步骤来理解这种尝试。

    <xsl:template match="/">
       <html>
          <head>
             <title><xsl:value-of select="PatDetails"/></title>
          </head>
          <body>
               <xsl:apply-templates/>
          </body>   
       </html>
    </xsl:template>
    
    <xsl:template match="PatDetails/Value">
        <h1><xsl:value-of select="."/></h1>
    </xsl:template>
    
    
    <xsl:template match="Impression/Value">
      <table border="1">
       <tr><td>                
         <xsl:for-each select=".">
             <xsl:value-of select="."/>
         </xsl:for-each>
       </td></tr>
      </table>
    </xsl:template>
    

    【讨论】:

    • 谢谢你,Artemis 我尝试了上面给出的 XSLT,但它不起作用。基本上我想有一个我想在所有页面上打印的报告标题。如果我们有一个由 4 页组成的患者记录..我想在所有四个页面中打印患者姓名作为标题或标题来标识每一页。我试过使用 标签,但它破坏了过去使用它的 UI 格式。如果您需要任何信息,请告诉我谢谢 Uday
    • 你想产生什么样的输出?一个word文档,html,xml?您已将输出作为 xml,其中页眉和页脚有点奇怪,因为您的数据出现在一页中。但我猜你的意思是你需要一个文本文件输出。
    • 是的,我想在 Web 浏览器中显示输出,使用 XML 和使用 XSLT 的布局或格式。如果我们单击此网页上的打印预览,您可以看到 ------------当我们使用 XML 打印 XSLT 报告时显示所有页面的页面标题-----作为页面顶部所有四个页面的标题。我想使用 XML 和 XSLT 做同样的事情。如果您需要更多信息,请告诉我
    • 别管阿耳忒弥斯,我能找到解决办法。
    • 谢谢阿耳忒弥斯。我可以找到答案。无论如何,感谢您的时间和帮助。以下是通过修改您的答案对我有用的答案..
    【解决方案2】:

    XSLT 代码

        <head>
    
    <title>
    
    
                            <xsl:call-template name="string-replace">
                                <xsl:with-param name="arg" select="Report/PatDetails"/>
                                <xsl:with-param name="toReplace" select="'^'"/>
                            </xsl:call-template>
    
    
    </title>
    
    </head> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      相关资源
      最近更新 更多