Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XML打印XSLT报告时显示所有页面的页面标题_Xml_Xslt_Header_Report_Title - Fatal编程技术网

使用XML打印XSLT报告时显示所有页面的页面标题

使用XML打印XSLT报告时显示所有页面的页面标题,xml,xslt,header,report,title,Xml,Xslt,Header,Report,Title,我想通过在所有页面中使用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:outpu

我想通过在所有页面中使用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>
    <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> 

p{线高度:“1”}
br{线高度:“1pt”}
br/>;
下面是我的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>

病人编号:@9999
1. @测试1
2. @测试2
3. @测试3
4. @测试4
5. @测试5
6. @测试6
7. @测试7
8. @测试8
1. @测试1
2. @测试2
3. @测试3
4. @测试4
5. @测试5
6. @测试6
7. @测试7
8. @测试8
1. @测试1
2. @测试2
3. @测试3
4. @测试4
5. @测试5
6. @测试6
7. @测试7
8. @测试8

我不确定您到底想做什么,但似乎您需要阅读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>

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>
    <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> 


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