如何使用disable-output-escaping输出xml字符

时间:2013-07-23 20:14:45

标签: xslt xslt-1.0 xslt-2.0

我正在使用xslt来转换xml文档。我需要使用输出转义来获取我的结果,因为我正在使用的工作服务器只会输出<site/>的结束标记,无论我尝试做什么。我发现这句话证实了我的问题。

“XSLT输出结果树,它不输出标签(除非你使用disable-output-escaping hack)。它是串行器,它接受结果树并生成适当的标签。如果你正在生成XML,请使用<xsl:output method="xml"/>。序列化程序将决定是使用<textarea></textarea>还是<textarea/>。在XML中,两种形式都是完全等效的,因此XML的任何使用者都会接受。“

我希望我的结果文档看起来像

<?xml version="1.0" encoding="utf-8"?>
<sites>
   <site>
      <pole>
            NAM
        </pole>
      <territory>
            Northeast
        </territory>
      <position>
            FSR
        </position>
      <platform>
            Mobile
        </platform>
      <latitude>
            -76.631056373393
        </latitude>
      <longitude>
            36.98237439172
        </longitude>
      <firstName>
            Justin
        </firstName>
      <lastName>
            Rhodes
        </lastName>
   </site>
   <site>
      <pole>
            NAM
        </pole>
      <territory>
            Northeast
        </territory>
      <position>
            FSR
        </position>
      <platform>
            Mobile
        </platform>
      <latitude>
            -71.454786492200
        </latitude>
      <longitude>
            42.995647573539
        </longitude>
      <firstName>
            Kevin
        </firstName>
      <lastName>
            Woods
        </lastName>
   </site>
</sites>

我正在使用以下xslt文档:

 <?xml version="1.0" encoding="UTF-8"?>

<!-- New document created with EditiX at Mon Jun 03 12:57:03 EDT 2013 -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output omit-xml-declaration="no" indent="yes"/>
    <xsl:output method = "xml"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">

        <sites>
        <xsl:for-each select="/ViewAll/ROW">

            <site>
                <pole>
            <xsl:value-of select="SC_DF_FIELD_1/text()"/>
                </pole>
                <territory>
            <xsl:value-of select="SC_DF_FIELD_2/text()"/>
                </territory>
                <position>
            <xsl:value-of select="SC_DF_FIELD_3/text()"/>
                </position>
                <platform>
            <xsl:value-of select="SC_DF_FIELD_4/text()"/>
                </platform>
                <latitude>
            <xsl:value-of select="SC_DF_FIELD_5/text()"/>
                </latitude>
                <longitude>
            <xsl:value-of select="SC_DF_FIELD_6/text()"/>
                </longitude>
                <firstName>
            <xsl:value-of select="SC_DF_FIELD_8/text()"/>
                </firstName>
                <lastName>
            <xsl:value-of select="SC_DF_FIELD_9/text()"/>
                </lastName>
            </site>

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

        <xsl:apply-templates/>

    </xsl:template>
    <!--This causes everything else in the document output to be ignored -->
    <xsl:template match="text()"/>
</xsl:stylesheet>

我正在将xslt应用于此xml:

 <?xml version="1.0"?>

    <?xml-stylesheet type="text/xsl" href="myFirstTemplate4.xsl"?>
    <ViewAll>
    <RECORDSET_METADATA>
        <STARTREC>1</STARTREC>
        <KEYFIELDS>False</KEYFIELDS>
        <ENDREC>2</ENDREC>
        <TOTALREC>2</TOTALREC>
        <PAme_NO>1</PAme_NO>
        <SORT_TYPE>DT_UPDATED</SORT_TYPE>
        <SORT_ORDER>desc</SORT_ORDER>
        <FORM_ID>427384</FORM_ID>
        <REPORT_ID></REPORT_ID>
        <SAVED_ID></SAVED_ID>
        <NEXTSORTORDER>
            <![CDATA[&sortorder=desc]]>
        </NEXTSORTORDER>
        <SC_DF_XSL_HELP_URL>
            <![CDATA[http://libraries.me.com/LibrariesWiki/2767051101/Data%20Forms%20- %20Customizing%20Records%20View]]>
        </SC_DF_XSL_HELP_URL>
        <FILTER_DATA>
            <![CDATA[var AdvSrchFltrXML_String =  { AdvSrchFltrData  : { filter : [ {selElementType  : '',selElementParentDF  : '',selComb  : '',exclCheck  : '',selElement  : '',query  : '',query_psrch  : '',includeNull  : '',lockFilter  : '',lockFilterFlg  : '',dateFrom  : '',dateTo  : '',betweenDaysFrom  : '',betweenDaysTo  : '',betweenDaysFromOption  : '',betweenDaysToOption  : '',exactDaysOption  : '',exactDays  : '',moreThanOption  : '',moreThan  : '',NumAgingQuery  : '',betweenNumFrom  : '',betweenNumTo  : '',GreaterOrLessOrEqualToNum  : '',dateFromFormat  : '',dateToFormat  : ''} ] },size : 1, HiddenXMLFilterCount :''}]]>
        </FILTER_DATA>
        <FILTER_FIELDS>
            <![CDATA[ var arrFields = new Array(new Array("form_doc_id","Entry #","req","","","","",""),new Array("LOGmeD_BY","Logmed By","psrch","","","","","1"),new Array("DT_LOGmeD","Date Logmed","dt","","","","",""),new Array("LAST_UPDATED_BY","Last Updated By","psrch","","","","","1"),new Array("DT_UPDATED","Date Updated","dt","","","","",""))]]>
        </FILTER_FIELDS>
        <meNERATE_HIDDEN_VAR>
            <![CDATA[]]>
        </meNERATE_HIDDEN_VAR>
        <HIDDEN_XML_FILTER_COUNT>
            <![CDATA[]]>
        </HIDDEN_XML_FILTER_COUNT>
        <HIDDEN_FILTER_REMOVE_NUMBER>
            <![CDATA[]]>
        </HIDDEN_FILTER_REMOVE_NUMBER>
        <DF_LINK_FIELDS_VAR>
            <![CDATA[]]>
        </DF_LINK_FIELDS_VAR>
        <SA_UPLOAD_FLAG>
            <![CDATA[-1]]>
        </SA_UPLOAD_FLAG>
        <FLG_EXPORT_PDF_WORD>0</FLG_EXPORT_PDF_WORD>
        <FLG_DISABLE_BULK_UPDATE_APPEND>0</FLG_DISABLE_BULK_UPDATE_APPEND>
        <FLG_EXPORT_KML>1</FLG_EXPORT_KML>
        <FLG_EXPORT_TO_MAP>0</FLG_EXPORT_TO_MAP>
        <PUBLISHED_FLAG>0</PUBLISHED_FLAG>
        <STR_CREATE_ORDER>402</STR_CREATE_ORDER>
        <FUNC_CREATE_ORDER>asc</FUNC_CREATE_ORDER>
        <FORM_NAME>Map Points</FORM_NAME>
        <PROD_ID>267672</PROD_ID>
        <ARCHIVE_FLAG>0</ARCHIVE_FLAG>
        <FACILITATOR_FLAG>1</FACILITATOR_FLAG>
        <ADVANCED_SEARCH_FLAG>1</ADVANCED_SEARCH_FLAG>
        <EXPORT_ALL_FLAG>1</EXPORT_ALL_FLAG>
        <EXPORT_PAme_FLAG>0</EXPORT_PAme_FLAG>
        <DELETE_RECORD_FLAG>1</DELETE_RECORD_FLAG>
        <FIELDCHOOSER_EDIT_FLAG>1</FIELDCHOOSER_EDIT_FLAG>
        <FIELDCHOOSER_COPY_FLAG>1</FIELDCHOOSER_COPY_FLAG>
        <RSS_FEED>1</RSS_FEED>
        <FIELD_CHOOSER_ENABLE_FLAG>1</FIELD_CHOOSER_ENABLE_FLAG>
        <ARCHIVE_ALL_ENABLE_FLAG>1</ARCHIVE_ALL_ENABLE_FLAG>
        <TRUNCATE_TEXT_FLAG>0</TRUNCATE_TEXT_FLAG>
        <CALLED_FOR></CALLED_FOR>
        <CALLING_ENTITY_TYPE></CALLING_ENTITY_TYPE>
        <EXCELUPLOADFLAG>true</EXCELUPLOADFLAG>
        <VIEWAUDITTRAIL>1</VIEWAUDITTRAIL>
        <STATICSERVER>//supportcentral.mecdn.com</STATICSERVER>
        <VIEWERS_DETAIL>
            <V_SSO_ID>218012021</V_SSO_ID>
            <V_PERSON_ID>1273277</V_PERSON_ID>
            <V_FIRST_NAME>meoffrey</V_FIRST_NAME>
            <V_LAST_NAME>melinas</V_LAST_NAME>
            <V_BUSINESS_SEGMENT>Power &amp; Water</V_BUSINESS_SEGMENT>
            <V_FOCUS_GROUP>me Power &amp; Water</V_FOCUS_GROUP>
            <V_SUB_BUSINESS>PW-WTR Water</V_SUB_BUSINESS>
            <V_LANGUAme>english</V_LANGUAme>
            <V_FUNCTION>Services</V_FUNCTION>
        </VIEWERS_DETAIL>
    </RECORDSET_METADATA>
    <DFLINK_ELEMENT_DETAILS>
        <CalledForSF display_name="CalledForSF" search_field="No">&amp;nbsp</CalledForSF>
        <SOURCE_ELEMENT_ID display_name="SOURCE_ELEMENT_ID" search_field="No">&amp;nbsp</SOURCE_ELEMENT_ID>
        <TARmeT_ELEMENT_ID display_name="TARmeT_ELEMENT_ID" search_field="No">&amp;nbsp</TARmeT_ELEMENT_ID>
    </DFLINK_ELEMENT_DETAILS>
    <DF_FIELDS>
        <SC_SYS_DF_FORM_DOC_ID display_name="Entry #" search_field="Yes">Entry #</SC_SYS_DF_FORM_DOC_ID>
        <SC_SYS_DF_DT_LOGmeD display_name="Date Logmed" search_field="Yes">Logmed Date</SC_SYS_DF_DT_LOGmeD>
        <SC_SYS_DF_DT_UPDATED display_name="Date Updated" search_field="Yes">Last Updated Date</SC_SYS_DF_DT_UPDATED>
        <SC_SYS_DF_LOGmeD_BY display_name="Logmed By" search_field="Yes">Logmed by</SC_SYS_DF_LOGmeD_BY>
        <SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By" search_field="Yes">Last Updated By</SC_SYS_DF_LAST_UPDATED_BY>
        <SC_SYS_DF_AUDIT_TRAIL_HEADER display_name="Audit Trail" search_field="Yes">Audit Trail</SC_SYS_DF_AUDIT_TRAIL_HEADER>
    </DF_FIELDS>
    <HEADER>
        <SC_SYS_DF_FORM_DOC_ID display_name="Entry #" search_field="Yes">Entry #</SC_SYS_DF_FORM_DOC_ID>
        <SC_SYS_DF_DT_LOGmeD display_name="Date Logmed" search_field="Yes">Logmed Date</SC_SYS_DF_DT_LOGmeD>
        <SC_SYS_DF_DT_UPDATED display_name="Date Updated" search_field="Yes">Last Updated Date</SC_SYS_DF_DT_UPDATED>
        <SC_SYS_DF_LOGmeD_BY display_name="Logmed By" search_field="Yes">Logmed by</SC_SYS_DF_LOGmeD_BY>
        <SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By" search_field="Yes">Last Updated By</SC_SYS_DF_LAST_UPDATED_BY>
        <SC_SYS_DF_AUDIT_TRAIL display_name="Audit Trail" search_field="Yes">Audit Trail</SC_SYS_DF_AUDIT_TRAIL>
        <SC_DF_FIELD_1 display_name="Poll" element_type="d" el_values="NAM;LAM;APAC;EUR;MEA" search_field="No">Poll</SC_DF_FIELD_1>
        <SC_DF_FIELD_2 display_name="Territory" element_type="d" el_values="Northeast;Southeast;Midwest;West;Plains;Canada" search_field="No">Territory</SC_DF_FIELD_2>
        <SC_DF_FIELD_3 display_name="Position" element_type="d" el_values="FSR" search_field="No">Position</SC_DF_FIELD_3>
        <SC_DF_FIELD_4 display_name="Platform" element_type="d" el_values="BOO;Mobile;UF/MBR;Captial" search_field="No">Platform</SC_DF_FIELD_4>
        <SC_DF_FIELD_5 display_name="Longitude" element_type="t" search_field="No">Longitude</SC_DF_FIELD_5>
        <SC_DF_FIELD_6 display_name="Latitude" element_type="t" search_field="No">Latitude</SC_DF_FIELD_6>
        <SC_DF_FIELD_8 display_name="First Name" element_type="t" search_field="No">First Name</SC_DF_FIELD_8>
        <SC_DF_FIELD_9 display_name="Last Name" element_type="t" search_field="No">Last Name</SC_DF_FIELD_9>
    </HEADER>
    <ROW edit_access="1">
        <SC_SYS_DF_FORM_DOC_ID_ACTION display_name="Entry # For Actions">
            <![CDATA[6526927427]]>
        </SC_SYS_DF_FORM_DOC_ID_ACTION>
        <SC_SYS_DF_FORM_DOC_ID display_name="Entry #">
            <![CDATA[6526927427]]>
            <ENTRY_VIEW_URL display_name="View Entry URL">
                <![CDATA[http://supportcentral.me.com/dataforms/sup_dataform_display.asp?dataform_id=427384&dataform_doc_id=6526927427]]>
            </ENTRY_VIEW_URL>
        </SC_SYS_DF_FORM_DOC_ID>
        <SC_SYS_DF_DT_LOGmeD display_name="Date Logmed">
            <![CDATA[6/3/2013 11:48:27 AM]]>
        </SC_SYS_DF_DT_LOGmeD>
        <SC_SYS_DF_DT_UPDATED display_name="Date Updated">
            <![CDATA[6/3/2013 11:48:27 AM]]>
        </SC_SYS_DF_DT_UPDATED>
        <SC_SYS_DF_LOGmeD_BY display_name="Logmed By">
            <![CDATA[&nbsp]]>
            <PERSON>
                <SC_DF_PERSON_LINK display_name="Profile Url">
                    <![CDATA[../common/sup_persondtls.asp?p_id=1273277]]>
                </SC_DF_PERSON_LINK>
                <SC_DF_SSO display_name="">
                    <![CDATA[218012021]]>
                </SC_DF_SSO>
                <SC_DF_EMAIL display_name="Email">
                    <![CDATA[meoffrey.melinas@me.com]]>
                </SC_DF_EMAIL>
                <SC_DF_FIRST_NAME display_name="First Name">
                    <![CDATA[meoffrey]]>
                </SC_DF_FIRST_NAME>
                <SC_DF_LAST_NAME display_name="Last Name">
                    <![CDATA[melinas]]>
                </SC_DF_LAST_NAME>
            </PERSON>
            <PERSON_STRING>
                <PERSON_STRING_VAR display_name="person person person">
                    <![CDATA[var person_String = {person : [ {PERSON_ID  : '../common/sup_persondtls.asp?p_id=1273277',FIRST_NAME  : 'meoffrey',LAST_NAME:'melinas'}], size : 1 }]]>
                </PERSON_STRING_VAR>
            </PERSON_STRING>
        </SC_SYS_DF_LOGmeD_BY>
        <SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By">
            <![CDATA[&nbsp]]>
            <PERSON>
                <SC_DF_PERSON_LINK display_name="Profile Url">
                    <![CDATA[../common/sup_persondtls.asp?p_id=1273277]]>
                </SC_DF_PERSON_LINK>
                <SC_DF_SSO display_name="">
                    <![CDATA[218012021]]>
                </SC_DF_SSO>
                <SC_DF_EMAIL display_name="Email">
                    <![CDATA[meoffrey.melinas@me.com]]>
                </SC_DF_EMAIL>
                <SC_DF_FIRST_NAME display_name="First Name">
                    <![CDATA[meoffrey]]>
                </SC_DF_FIRST_NAME>
                <SC_DF_LAST_NAME display_name="Last Name">
                    <![CDATA[melinas]]>
                </SC_DF_LAST_NAME>
            </PERSON>
            <PERSON_STRING>
                <PERSON_STRING_VAR display_name="person person person">
                    <![CDATA[var person_String = {person : [ {PERSON_ID  : '../common/sup_persondtls.asp?p_id=1273277',FIRST_NAME  : 'meoffrey',LAST_NAME:'melinas'}], size : 1 }]]>
                </PERSON_STRING_VAR>
            </PERSON_STRING>
        </SC_SYS_DF_LAST_UPDATED_BY>
        <SC_SYS_DF_AUDIT_TRAIL display_name="Audit Trail">
            <![CDATA[<a href="../caseforms/complete_audit_trail.asp?calling_entity_id=427384&form_doc_id=6526927427&pameNo=0&auditType=0&callinmentity=4" tarmet="_none">Audit Trail</a>]]>
        </SC_SYS_DF_AUDIT_TRAIL>
        <SC_DF_FIELD_1 display_name="Poll" element_type="d">
            <![CDATA[NAM]]>
        </SC_DF_FIELD_1>
        <SC_DF_FIELD_2 display_name="Territory" element_type="d">
            <![CDATA[Northeast]]>
        </SC_DF_FIELD_2>
        <SC_DF_FIELD_3 display_name="Position" element_type="d">
            <![CDATA[FSR]]>
        </SC_DF_FIELD_3>
        <SC_DF_FIELD_4 display_name="Platform" element_type="d">
            <![CDATA[Mobile]]>
        </SC_DF_FIELD_4>
        <SC_DF_FIELD_5 display_name="Longitude" element_type="t" data_type="alpha">
            <![CDATA[-76.631056373393]]>
        </SC_DF_FIELD_5>
        <SC_DF_FIELD_6 display_name="Latitude" element_type="t" data_type="alpha">
            <![CDATA[36.98237439172]]>
        </SC_DF_FIELD_6>
        <SC_DF_FIELD_8 display_name="First Name" element_type="t" data_type="alpha">
            <![CDATA[Justin]]>
        </SC_DF_FIELD_8>
        <SC_DF_FIELD_9 display_name="Last Name" element_type="t" data_type="alpha">
            <![CDATA[Rhodes]]>
        </SC_DF_FIELD_9>
    </ROW>
    <ROW edit_access="1">
        <SC_SYS_DF_FORM_DOC_ID_ACTION display_name="Entry # For Actions">
            <![CDATA[6526927192]]>
        </SC_SYS_DF_FORM_DOC_ID_ACTION>
        <SC_SYS_DF_FORM_DOC_ID display_name="Entry #">
            <![CDATA[6526927192]]>
            <ENTRY_VIEW_URL display_name="View Entry URL">
                <![CDATA[http://supportcentral.me.com/dataforms/sup_dataform_display.asp?dataform_id=427384&dataform_doc_id=6526927192]]>
            </ENTRY_VIEW_URL>
        </SC_SYS_DF_FORM_DOC_ID>
        <SC_SYS_DF_DT_LOGmeD display_name="Date Logmed">
            <![CDATA[6/3/2013 11:47:41 AM]]>
        </SC_SYS_DF_DT_LOGmeD>
        <SC_SYS_DF_DT_UPDATED display_name="Date Updated">
            <![CDATA[6/3/2013 11:47:41 AM]]>
        </SC_SYS_DF_DT_UPDATED>
        <SC_SYS_DF_LOGmeD_BY display_name="Logged By">
            <![CDATA[&nbsp]]>
            <PERSON>
                <SC_DF_PERSON_LINK display_name="Profile Url">
                    <![CDATA[../common/sup_persondtls.asp?p_id=1273277]]>
                </SC_DF_PERSON_LINK>
                <SC_DF_SSO display_name="">
                    <![CDATA[218012021]]>
                </SC_DF_SSO>
                <SC_DF_EMAIL display_name="Email">
                    <![CDATA[meoffrey.melinas@me.com]]>
                </SC_DF_EMAIL>
                <SC_DF_FIRST_NAME display_name="First Name">
                    <![CDATA[meoffrey]]>
                </SC_DF_FIRST_NAME>
                <SC_DF_LAST_NAME display_name="Last Name">
                    <![CDATA[melinas]]>
                </SC_DF_LAST_NAME>
            </PERSON>
            <PERSON_STRING>
         <PERSON_STRING_VAR display_name="person person person">
         <![CDATA[var person_String = {person : [ {PERSON_ID  : '../common/sup_persondtls.asp?p_id=1273277',FIRST_NAME  : 'meoffrey',LAST_NAME:'melinas'}], size : 1 }]]>
                </PERSON_STRING_VAR>
            </PERSON_STRING>
        </SC_SYS_DF_LOGmeD_BY>
        <SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By">
            <![CDATA[&nbsp]]>
            <PERSON>
                <SC_DF_PERSON_LINK display_name="Profile Url">
                    <![CDATA[../common/sup_persondtls.asp?p_id=1273277]]>
                </SC_DF_PERSON_LINK>
                <SC_DF_SSO display_name="">
                    <![CDATA[218012021]]>
                </SC_DF_SSO>
                <SC_DF_EMAIL display_name="Email">
                    <![CDATA[meoffrey.melinas@me.com]]>
                </SC_DF_EMAIL>
                <SC_DF_FIRST_NAME display_name="First Name">
                    <![CDATA[meoffrey]]>
                </SC_DF_FIRST_NAME>
                <SC_DF_LAST_NAME display_name="Last Name">
                    <![CDATA[melinas]]>
                </SC_DF_LAST_NAME>
            </PERSON>
            <PERSON_STRING>
                <PERSON_STRING_VAR display_name="person person person">
                    <![CDATA[var person_String = {person : [ {PERSON_ID  : '../common/sup_persondtls.asp?p_id=1273277',FIRST_NAME  : 'meoffrey',LAST_NAME:'melinas'}], size : 1 }]]>
                </PERSON_STRING_VAR>
            </PERSON_STRING>
        </SC_SYS_DF_LAST_UPDATED_BY>
        <SC_SYS_DF_AUDIT_TRAIL display_name="Audit Trail">
            <![CDATA[<a href="../caseforms/complete_audit_trail.asp?calling_entity_id=427384&form_doc_id=6526927192&pameNo=0&auditType=0&callinmentity=4" tarmet="_none">Audit Trail</a>]]>
        </SC_SYS_DF_AUDIT_TRAIL>
        <SC_DF_FIELD_1 display_name="Poll" element_type="d">
            <![CDATA[NAM]]>
        </SC_DF_FIELD_1>
        <SC_DF_FIELD_2 display_name="Territory" element_type="d">
            <![CDATA[Northeast]]>
        </SC_DF_FIELD_2>
        <SC_DF_FIELD_3 display_name="Position" element_type="d">
            <![CDATA[FSR]]>
        </SC_DF_FIELD_3>
        <SC_DF_FIELD_4 display_name="Platform" element_type="d">
            <![CDATA[Mobile]]>
        </SC_DF_FIELD_4>
        <SC_DF_FIELD_5 display_name="Longitude" element_type="t" data_type="alpha">
            <![CDATA[-71.454786492200]]>
        </SC_DF_FIELD_5>
        <SC_DF_FIELD_6 display_name="Latitude" element_type="t" data_type="alpha">
            <![CDATA[42.995647573539]]>
        </SC_DF_FIELD_6>
        <SC_DF_FIELD_8 display_name="First Name" element_type="t" data_type="alpha">
            <![CDATA[Kevin]]>
        </SC_DF_FIELD_8>
        <SC_DF_FIELD_9 display_name="Last Name" element_type="t" data_type="alpha">
            <![CDATA[Woods]]>
        </SC_DF_FIELD_9>
    </ROW>
    </ViewAll>

关于如何获得我想要的结果的任何想法?

提前致谢!

1 个答案:

答案 0 :(得分:0)

当使用Saxon运行时,您提供的XSLT代码会产生(据我所知)您正在寻找的输出。您的输出有何不同,以及如何获得它?

您当然似乎不需要禁用 - 输出 - 转义。

你的问题无论如何都很困惑。你说你得到的是“<site/>的结束标记,无论你做什么”,但是(a)<site/>不是结束标记,它是一个空元素标记,并且(b)你不要解释为什么你不想要一个结束标签。你说你想要输出转义,这是正常的默认值,所以为什么你对禁用输出转义感兴趣,这会将其关闭?