2016-11-30 70 views
0

愚蠢的問題,具體的節點,但希望我可以在這裏得到一些幫助,我需要訪問特定節點的XSL,我提供了看起來像下面的XML,能有人給我一個想法是什麼我XSL應該看起來像要訪問我不能不管我如何努力達到這個節點的節點「值」的內容 - 任何幫助讚賞!!!! :如何訪問XSL

<?xml version="1.0" encoding="UTF-8" ?> 
<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="urn:crystal-reports:schemas:report-detail http://www.businessobjects.com/products/xml/CR2008Schema.xsd"> 
<Group Level="1"> 
    <Group Level="2"> 
     <Details Level="3"> 
      <Section SectionNumber="1"> 
       <Field Name="Field5" FieldName="{ARTransaction.Transactions}"> 
        <FormattedValue>0.00</FormattedValue> 
        <Value>0.00</Value> 
       </Field> 
       <Field Name="Field15" FieldName="{ARTransaction.PostingDate}"> 
        <FormattedValue>8/1/2016</FormattedValue> 
        <Value>2016-08-01</Value> 
       </Field> 
       <Field Name="Field14" FieldName="{ARTransaction.AuditTrail}"> 
        <FormattedValue>2016083100154</FormattedValue> 
        <Value>2016083100154</Value> 
       </Field> 
       <Field Name="Field13" FieldName="{ARTransaction.JobN}"> 
        <FormattedValue>-25043</FormattedValue> 
        <Value>-25043</Value> 
       </Field> 
       <Field Name="Field11" FieldName="{Customer.CustomerName}"> 
        <FormattedValue>First Church of Christ</FormattedValue> 
        <Value>First Church of Christ</Value> 
       </Field> 
       <Field Name="Field7" FieldName="{ARTransaction.CustomerN}"> 
        <FormattedValue>13157</FormattedValue> 
        <Value>13157</Value> 
       </Field> 
       <Field Name="Field6" FieldName="{ARTransaction.InvoiceN}"> 
        <FormattedValue>25043</FormattedValue> 
        <Value>25043</Value> 
       </Field> 
       <Field Name="SalesmanN1" FieldName="{ARTransaction.SalesmanN}"> 
        <FormattedValue>22</FormattedValue> 
        <Value>22</Value> 
       </Field> 
      </Section> 
     </Details> 
    </Group> 
    </Group> 
</Group> 
<ReportFooter> </ReportFooter> 

XSL:

<xsl:output method="xml" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:element name="CrystalReport"> 
     <xsl:attribute name="xsi:schemaLocation">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute> 
     <xsl:attribute name="version">1.2</xsl:attribute>  
    </xsl:element> 
    <xsl:element name="DR"> 
    <xsl:value-of select="Group/Group/Details/Section/Field[@Name='Field13']/Value"/> 
    </xsl:element> 

</xsl:template> 

+0

請提供一個完整的XML以及預期的結果(參見:[MCVE])。在你的輸入中有幾個'Value'元素,所以你的請求不清楚。 –

+0

對不起 - 我非常清楚! 以下XML是完整的一個,我想訪問「價值」,其中字段名稱=「Field13」,我不知道如何使用XSL來達到這個....的節點 – DPR

+0

那麼你嘗試過什麼? –

回答

0

與你嘗試的主要問題是,它忽略源XML的默認命名空間

您需要聲明的命名空間在樣式表中,爲它分配一個前綴,並解決了源XML元素時使用該前綴。例如,下面的樣式表:

XSL 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ns1="urn:crystal-reports:schemas:report-detail" 
exclude-result-prefixes="ns1"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/ns1:CrystalReport"> 
    <DR> 
     <xsl:value-of select="ns1:Group/ns1:Group/ns1:Details/ns1:Section/ns1:Field[@Name='Field13']/ns1:Value"/> 
    </DR> 
</xsl:template> 

</xsl:stylesheet> 

當應用於合式輸入如:

XML

<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:crystal-reports:schemas:report-detail http://www.businessobjects.com/products/xml/CR2008Schema.xsd"> 
    <Group Level="1"> 
    <Group Level="2"> 
     <Details Level="3"> 
     <Section SectionNumber="1"> 
      <Field Name="Field5" FieldName="{ARTransaction.Transactions}"> 
      <FormattedValue>0.00</FormattedValue> 
      <Value>0.00</Value> 
      </Field> 
      <Field Name="Field15" FieldName="{ARTransaction.PostingDate}"> 
      <FormattedValue>8/1/2016</FormattedValue> 
      <Value>2016-08-01</Value> 
      </Field> 
      <Field Name="Field14" FieldName="{ARTransaction.AuditTrail}"> 
      <FormattedValue>2016083100154</FormattedValue> 
      <Value>2016083100154</Value> 
      </Field> 
      <Field Name="Field13" FieldName="{ARTransaction.JobN}"> 
      <FormattedValue>-25043</FormattedValue> 
      <Value>-25043</Value> 
      </Field> 
      <Field Name="Field11" FieldName="{Customer.CustomerName}"> 
      <FormattedValue>First Church of Christ</FormattedValue> 
      <Value>First Church of Christ</Value> 
      </Field> 
      <Field Name="Field7" FieldName="{ARTransaction.CustomerN}"> 
      <FormattedValue>13157</FormattedValue> 
      <Value>13157</Value> 
      </Field> 
      <Field Name="Field6" FieldName="{ARTransaction.InvoiceN}"> 
      <FormattedValue>25043</FormattedValue> 
      <Value>25043</Value> 
      </Field> 
      <Field Name="SalesmanN1" FieldName="{ARTransaction.SalesmanN}"> 
      <FormattedValue>22</FormattedValue> 
      <Value>22</Value> 
      </Field> 
     </Section> 
     </Details> 
    </Group> 
    </Group> 
</CrystalReport> 

將回報:

結果

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

注意:如果您使用的是XSLT 2.0處理器,可以聲明xpath-default-namespace屬性和廢除的前綴。

+0

太感謝你了!星!!!! – DPR