XSLT From File Different than WebService

2019-07-26 08:20发布

问题:

I am doing some XSLT - in one case I have a service that serializes to an XML file and my XSLT will pull this. In another case I have a webservice serialize the same object. The outputs are , as far as I can tell, identical. But the XQuery/XPath for the XML File does not work for the XML REST Service.

For example look at this picture that shows me loading a document from both sources and evaluating the same path for each.

How are these different? Why do they not evaluate the same?

update

XML From the File:

  <?xml version="1.0" encoding="utf-8"?>
<ArrayOfBusinessGroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <BusinessGroup>
    <ListofSkills>
      <SkillClass>
        <SkillName>DTE</SkillName>
        <InteractionCount>0</InteractionCount>
      </SkillClass>
      <SkillClass>
        <SkillName>FIN</SkillName>
        <InteractionCount>0</InteractionCount>
      </SkillClass>
      <SkillClass>
        <SkillName>DPS</SkillName>
        <InteractionCount>0</InteractionCount>
      </SkillClass>
      <SkillClass>
        <SkillName>PPD Apps</SkillName>
        <InteractionCount>0</InteractionCount>
      </SkillClass>
      <SkillClass>
        <SkillName>FHD New</SkillName>
        <InteractionCount>0</InteractionCount>
      </SkillClass>
      <SkillClass>
        <SkillName>FHD Existing</SkillName>
        <InteractionCount>0</InteractionCount>
      </SkillClass>
    </ListofSkills>
    <GroupName>Apps Chat</GroupName>
  </BusinessGroup>

XML From the Webservice:

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfBusinessGroup xmlns="http://schemas.datacontract.org/2004/07/ININ.WCF.DeloitteSIC.Models" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<BusinessGroup>
<GroupName>Apps Chat</GroupName>
<ListofSkills>
<SkillClass>
<InteractionCount>2</InteractionCount>
<SkillName>DTE</SkillName>
</SkillClass>
<SkillClass>
<InteractionCount>0</InteractionCount>
<SkillName>FIN</SkillName>
</SkillClass>
<SkillClass>
<InteractionCount>0</InteractionCount>
<SkillName>DPS</SkillName>
</SkillClass>
<SkillClass>
<InteractionCount>0</InteractionCount>
<SkillName>PPD Apps</SkillName>
</SkillClass>
<SkillClass>
<InteractionCount>0</InteractionCount>
<SkillName>FHD New</SkillName>
</SkillClass>
<SkillClass>
<InteractionCount>0</InteractionCount>
<SkillName>FHD Existing</SkillName>
</SkillClass>
</ListofSkills>
</BusinessGroup>

回答1:

The issue here is that the XML returned from the webservice is using namespaces, but your XPaths are not. To properly use namespaces, you would:

Declare the namespace at the top of your XSLT (in the xsl:stylesheet tag):

xmlns:dc="http://schemas.datacontract.org/2004/07/ININ.WCF.DeloitteSIC.Models"

Then instead of referring to elements just by their names, you would prefix the names with the declared prefix:

$skillFile/dc:ArrayOfBusinessGroup/*[starts-with(dc:GroupName, $groupName)]


标签: xslt