如何编写XSLT中删除空间的代码? [英] how to write the code for deleteing space in XSLT?

查看:97
本文介绍了如何编写XSLT中删除空间的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我.

pls help me.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:ns1="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="ns0 ns1 xs">
  <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <Checklist xmlns="http://icap.atp.com/2011/02/Checklist">
      <xsl:attribute name="xsi:schemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance">http://icap.atp.com/2011/02/Checklist D:/XSLT/Checklist.xsd</xsl:attribute>
      <xsl:element name="System">

        <xsl:attribute name="label">
          <xsl:text>ORG</xsl:text>
        </xsl:attribute>

        <xsl:attribute name="title">
          <xsl:text>OPERATIONS</xsl:text>
        </xsl:attribute>

        <xsl:attribute name="displayorder">
          <xsl:text>0</xsl:text>
        </xsl:attribute>

        <xsl:for-each select="ns1:wordDocument/ns1:body/ns0:sect/ns1:tbl">
          <xsl:variable name="titlerow" select="ns1:tr[1]/ns1:tc[1]/ns1:p/ns1:r"/>

          <xsl:element name="Section">

            <xsl:variable name="looptitlerow">
              <xsl:for-each select="$titlerow">
                <xsl:value-of select="ns1:t"/>
              </xsl:for-each>
            </xsl:variable>

            <xsl:attribute name="label">
              <xsl:value-of select="normalize-space(translate(substring($looptitlerow,1,2),'.',''))"/>
            </xsl:attribute>

            <xsl:attribute name="title">
              <xsl:value-of select="normalize-space(translate(substring($looptitlerow,3),'.',''))"/>
            </xsl:attribute>

            <xsl:attribute name="displayorder">
              <xsl:value-of select="position()-1"/>
            </xsl:attribute>

              <xsl:element name="Questions">

                <xsl:for-each select="ns1:tr">
                <xsl:if test="position() != 1">
                    <xsl:variable name="hidden" select="ns1:tc/ns1:p/ns1:pPr/ns1:listPr/ns0:t/@ns0:val"/>
                    <xsl:variable name="Questionrow">
                       <xsl:for-each select="ns1:tc/ns1:p">
                        <xsl:choose>
                          <xsl:when test="ns1:pPr/ns1:listPr">
                            <xsl:variable name="one" select="ns0:t/@ns0:val">
                            </xsl:variable>

                            <xsl:variable name="two">
                              <xsl:for-each select="ns1:r">
                                <!--<xsl:if test="string-length(ns1:t) &lt; 0">-->
                                  <xsl:value-of select="(ns1:t)"/>
                                <!--</xsl:if>-->
                              </xsl:for-each>
                            </xsl:variable>

                            <xsl:value-of select="concat(normalize-space($hidden),' ' , normalize-space($two))"/>
                          </xsl:when>

                          <xsl:otherwise>
                            <xsl:for-each select="ns1:r">
                              <xsl:value-of select="ns1:t"/>
                            </xsl:for-each>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </xsl:variable>

                  <xsl:if test="string(number(substring(normalize-space($Questionrow),1,1)))='NaN'">

                  <xsl:element name="Question">
                    <xsl:choose>
                      <xsl:when test="string(number(substring(normalize-space($Questionrow),1,1)))='NaN'">

                        <xsl:attribute name="label">
                          <xsl:choose>
                            <xsl:when test="starts-with(normalize-space($Questionrow),'(')">
                              <xsl:value-of select="translate(substring(substring($Questionrow,2,2),1,1),'.','')"/>
                            </xsl:when>
                            <xsl:when test="starts-with(normalize-space($Questionrow),'�������� ')">
                              <xsl:value-of select="translate(substring(substring(substring($Questionrow,11),2,2),1,1),'.','')"/>
                            </xsl:when>
                            <xsl:otherwise>
                              <xsl:value-of select="translate(substring(normalize-space($Questionrow),1,1),'.','')"/>
                            </xsl:otherwise>
                          </xsl:choose>
                        </xsl:attribute>

                        <xsl:attribute name="displayorder">
                          <xsl:value-of select="position() - 2"/>
                        </xsl:attribute>

                        <xsl:attribute name="questiontype">
                          <xsl:text>DoDQuestion</xsl:text>
                        </xsl:attribute>

                        <xsl:element name="Text">
                          <!--<xsl:if test="starts-with("-->
                          <!--<xsl:value-of select="normalize-space($Questionrow)"/>-->
                          <xsl:choose>
                            <xsl:when test="starts-with(normalize-space($Questionrow),'�������� ')">
                              <xsl:value-of select="normalize-space(translate(substring($Questionrow,11),'.',''))"/>
                            </xsl:when>
                            <xsl:otherwise>
                              <xsl:value-of select="normalize-space(translate($Questionrow,'.',' '))"/>
                            </xsl:otherwise>
                          </xsl:choose>
                          <!--<xsl:variable name="length" select="string-length(substring-before(normalize-space($Questionrow),'?'))"/>
                          <xsl:value-of select="substring(normalize-space($Questionrow),3,($length))"/>-->
                        </xsl:element>

                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:element name="Subquestions">
                          <xsl:element name="Subquestion">
                           <!--<xsl:strip-space elements="subquestions"/>
                            <xsl:strip-space elements="Subquestion"/>-->
                            <xsl:attribute name="label">
                              <xsl:value-of select="translate(substring(normalize-space($Questionrow),1,1),'.','')"/>
                            </xsl:attribute>

                            <xsl:attribute name="displayorder">
                              <xsl:value-of select="position() - 2"/>
                            </xsl:attribute>

                            <xsl:attribute name="questiontype">
                              <xsl:text>DoDQuestion</xsl:text>
                            </xsl:attribute>

                            <xsl:element name="Text">
                              <!--<xsl:if test="starts-with("-->
                              <xsl:value-of select="translate(normalize-space($Questionrow),'.','')"/>
                              <!--<xsl:variable name="length" select="string-length(substring-before(normalize-space($Questionrow),'?'))"/>
                          <xsl:value-of select="substring(normalize-space($Questionrow),3,($length))"/>-->
                            </xsl:element>
                          </xsl:element>
                        </xsl:element>


                      </xsl:otherwise>
                    </xsl:choose>

                    <xsl:element name="AnswerChoices">

                      <xsl:element name="AnswerChoice">
                        <xsl:attribute name="code">
                          <xsl:text>Yes</xsl:text>
                        </xsl:attribute>

                        <xsl:attribute name="label">
                          <xsl:text>Yes</xsl:text>
                        </xsl:attribute>

                        <xsl:attribute name="displayorder">
                          <xsl:value-of select="0"/>
                        </xsl:attribute>

                        <xsl:attribute name="type">
                          <xsl:text>radio</xsl:text>
                        </xsl:attribute>

                      </xsl:element>

                      <xsl:element name="AnswerChoice">
                        <xsl:attribute name="code">
                          <xsl:text>No</xsl:text>
                        </xsl:attribute>

                        <xsl:attribute name="label">
                          <xsl:text>No</xsl:text>
                        </xsl:attribute>

                        <xsl:attribute name="displayorder">
                          <xsl:value-of select="1"/>
                        </xsl:attribute>

                        <xsl:attribute name="type">
                          <xsl:text>radio</xsl:text>
                        </xsl:attribute>

                      </xsl:element>

                      <xsl:element name="AnswerChoice">
                        <xsl:attribute name="code">
                          <xsl:text>NA</xsl:text>
                        </xsl:attribute>

                        <xsl:attribute name="label">
                          <xsl:text>N/A</xsl:text>
                        </xsl:attribute>

                        <xsl:attribute name="displayorder">
                          <xsl:value-of select="2"/>
                        </xsl:attribute>

                        <xsl:attribute name="type">
                          <xsl:text>radio</xsl:text>
                        </xsl:attribute>
                      </xsl:element>

                    </xsl:element>

                  </xsl:element>

                  </xsl:if>
                </xsl:if>
              </xsl:for-each>

              </xsl:element>

          </xsl:element>

        </xsl:for-each>


      </xsl:element>
    </Checklist>
  </xsl:template>

  <xsl:template name="noanswer">
    <AnswerChoice>
      <xsl:attribute name="code">
      </xsl:attribute>

      <xsl:attribute name="label">
      </xsl:attribute>

      <xsl:attribute name="displayorder">
        <xsl:value-of select="0"/>
      </xsl:attribute>

      <xsl:attribute name="type">
        <xsl:text>text</xsl:text>
      </xsl:attribute>
    </AnswerChoice>
  </xsl:template>

  <xsl:template name="threeanswers" >

    <AnswerChoice>
      <xsl:attribute name="code">
        <xsl:text>Yes</xsl:text>
      </xsl:attribute>

      <xsl:attribute name="label">
        <xsl:text>Yes</xsl:text>
      </xsl:attribute>

      <xsl:attribute name="displayorder">
        <xsl:value-of select="0"/>
      </xsl:attribute>

      <xsl:attribute name="type">
        <xsl:text>radio</xsl:text>
      </xsl:attribute>
    </AnswerChoice>

    <AnswerChoice>
      <xsl:attribute name="code">
        <xsl:text>No</xsl:text>
      </xsl:attribute>

      <xsl:attribute name="label">
        <xsl:text>No</xsl:text>
      </xsl:attribute>

      <xsl:attribute name="displayorder">
        <xsl:value-of select="1"/>
      </xsl:attribute>

      <xsl:attribute name="type">
        <xsl:text>radio</xsl:text>
      </xsl:attribute>
    </AnswerChoice>

    <AnswerChoice>
      <xsl:attribute name="code">
        <xsl:text>NA</xsl:text>
      </xsl:attribute>

      <xsl:attribute name="label">
        <xsl:text>N/A</xsl:text>
      </xsl:attribute>

      <xsl:attribute name="displayorder">
        <xsl:value-of select="2"/>
      </xsl:attribute>

      <xsl:attribute name="type">
        <xsl:text>radio</xsl:text>
      </xsl:attribute>
    </AnswerChoice>
  </xsl:template>

  <xsl:template name="question">

    <xsl:param name="tablerow"/>
    <xsl:param name="label"/>
    <xsl:param name="displayorder"/>

    <xsl:attribute name="label">
      <xsl:value-of select="$label"/>
    </xsl:attribute>

    <xsl:attribute name="displayorder">
      <xsl:value-of select="$displayorder"/>
    </xsl:attribute>

    <xsl:attribute name="questiontype">
      <xsl:text>DoDQuestion</xsl:text>
    </xsl:attribute>
  </xsl:template>

  <xsl:template name="subquestion" >

    <xsl:param name="tablerow"/>
    <xsl:param name="label"/>
    <xsl:param name="level"/>
    <xsl:param name="displayorder"/>

    <!--<xsl:for-each select="$tablerow">-->

    <xsl:attribute name="label">
      <xsl:value-of select="$label"/>
    </xsl:attribute>

    <xsl:attribute name="level">
      <xsl:value-of select="$level"/>
    </xsl:attribute>

    <xsl:attribute name="displayorder">
      <xsl:value-of select="$displayorder"/>
    </xsl:attribute>

    <xsl:attribute name="questiontype">
      <xsl:text>DoDQuestion</xsl:text>
    </xsl:attribute>

    <!--</xsl:for-each>-->
  </xsl:template>

</xsl:stylesheet>

推荐答案

titlerow"> <xsl:value-of select="ns1:t"/> < /xsl:for-each > < /xsl:variable > <xsl:attribute name="label"> <xsl:value-of select="normalize-space(translate(substring(
titlerow"> <xsl:value-of select="ns1:t"/> </xsl:for-each> </xsl:variable> <xsl:attribute name="label"> <xsl:value-of select="normalize-space(translate(substring(


looptitlerow,1,2),'.',''))"/> < /xsl:attribute > <xsl:attribute name="title"> <xsl:value-of select="normalize-space(translate(substring(
looptitlerow,1,2),'.',''))"/> </xsl:attribute> <xsl:attribute name="title"> <xsl:value-of select="normalize-space(translate(substring(


looptitlerow,3),'.',''))"/> < /xsl:attribute > <xsl:attribute name="displayorder"> <xsl:value-of select="position()-1"/> < /xsl:attribute > <xsl:element name="Questions"> <xsl:for-each select="ns1:tr"> <xsl:if test="position() != 1"> <xsl:variable name="hidden" select="ns1:tc/ns1:p/ns1:pPr/ns1:listPr/ns0:t/@ns0:val"/> <xsl:variable name="Questionrow"> <xsl:for-each select="ns1:tc/ns1:p"> < xsl:choose > <xsl:when test="ns1:pPr/ns1:listPr"> <xsl:variable name="one" select="ns0:t/@ns0:val"> < /xsl:variable > <xsl:variable name="two"> <xsl:for-each select="ns1:r"> <!--<xsl:if test="string-length(ns1:t) &lt; 0">--> <xsl:value-of select="(ns1:t)"/> <!--</xsl:if>--> < /xsl:for-each > < /xsl:variable > <xsl:value-of select="concat(normalize-space(
looptitlerow,3),'.',''))"/> </xsl:attribute> <xsl:attribute name="displayorder"> <xsl:value-of select="position()-1"/> </xsl:attribute> <xsl:element name="Questions"> <xsl:for-each select="ns1:tr"> <xsl:if test="position() != 1"> <xsl:variable name="hidden" select="ns1:tc/ns1:p/ns1:pPr/ns1:listPr/ns0:t/@ns0:val"/> <xsl:variable name="Questionrow"> <xsl:for-each select="ns1:tc/ns1:p"> <xsl:choose> <xsl:when test="ns1:pPr/ns1:listPr"> <xsl:variable name="one" select="ns0:t/@ns0:val"> </xsl:variable> <xsl:variable name="two"> <xsl:for-each select="ns1:r"> <!--<xsl:if test="string-length(ns1:t) &lt; 0">--> <xsl:value-of select="(ns1:t)"/> <!--</xsl:if>--> </xsl:for-each> </xsl:variable> <xsl:value-of select="concat(normalize-space(


这篇关于如何编写XSLT中删除空间的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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