Xslt broken: pattern does not match

I am trying to request an xml file using the following xslt:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
                xmlns:bpmn="http://dkm.fbk.eu/index.php/BPMN_Ontology">

<!-- Participants -->
<xsl:template match="/">
<html>
    <body>
<table>
          <xsl:for-each select="Package/Participants/Participant">
                  <tr>
                    <td><xsl:value-of select="ParticipantType" /></td>
                    <td><xsl:value-of select="Description" /></td>
                  </tr>
          </xsl:for-each>
    </table>
       </body>
    </html>
</xsl:template> 
</xsl:stylesheet>

Here is the contents of the xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="xpdl2bpmn.xsl"?>
        <Package xmlns="http://www.wfmc.org/2008/XPDL2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Id="25ffcb89-a9bf-40bc-8f50-e5afe58abda0" Name="1 price setting" OnlyOneProcess="false">
      <PackageHeader>
        <XPDLVersion>2.1</XPDLVersion>
        <Vendor>BizAgi Process Modeler.</Vendor>
        <Created>2010-04-24T10:49:45.3442528+02:00</Created>
        <Description>1 price setting</Description>
        <Documentation />
      </PackageHeader>
      <RedefinableHeader>
        <Author />
        <Version />
        <Countrykey>CO</Countrykey>
      </RedefinableHeader>
      <ExternalPackages />
      <Participants>
        <Participant Id="008af9a6-fdc0-45e6-af3f-984c3e220e03" Name="customer">
          <ParticipantType Type="RESOURCE" />
          <Description />
        </Participant>
        <Participant Id="1d2fd8b4-eb88-479b-9c1d-7fe6c45b910e" Name="clerk">
          <ParticipantType Type="ROLE" />
          <Description />
        </Participant>
      </Participants>
</Package>

Despite a simple template, foreach does not work. What happened to the package / members / member ? What am I missing here? Is there something in namespaces that I don't get?

Thank you so much!

+3
source share
3 answers

There are a number of problems in your code :

  • Elements of the XML document are in the default namespace, but matching patterns (and select expressions) in XSLT code use elements in the "no namespace".

  • <xsl:value-of> ParticipantType Description, .

, XML- , ParticipantType Description .

: , XML, XSLT . XML.

XSLT :

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 xmlns:bpmn="http://dkm.fbk.eu/index.php/BPMN_Ontology"
 xmlns:xp="http://www.wfmc.org/2008/XPDL2.1"
>

<!-- Participants -->
<xsl:template match="/">
<html>
 <body>
  <table>
   <xsl:for-each select="xp:Package/xp:Participants/xp:Participant">
     <tr>
       <td><xsl:value-of select="xp:ParticipantType" /></td>
       <td><xsl:value-of select="xp:Description" /></td>
     </tr>
   </xsl:for-each>
  </table>
 </body>
</html>
</xsl:template>
</xsl:stylesheet>

xp:.

:

<html xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:bpmn="http://dkm.fbk.eu/index.php/BPMN_Ontology" xmlns:xp="http://www.wfmc.org/2008/XPDL2.1">
    <body>
        <table>
            <tr>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
            </tr>
        </table>
    </body>
</html>

1, <td> .

+10

XML . XSLT:

<xsl:for-each
  xmlns:xpdl2="http://www.wfmc.org/2008/XPDL2.1"
  select="xpdl2:Package/xpdl2:Participants/xpdl2:Participant">
        <tr>
          <td><xsl:value-of select="xpdl2:ParticipantType" /></td>
          <td><xsl:value-of select="xpdl2:Description" /></td>
        </tr>
</xsl:for-each>
0

Dimitre bkail XSLT, <ParticipantType> <Description> .

, , <ParticipantType>, Type (, "RESOURCE" "ROLE" ). , :

<td><xsl:value-of select="xp:ParticipantType/@Type" /></td

<Description> , - , , . , "" - , , "".

Roger_S

0
source

Source: https://habr.com/ru/post/1742590/


All Articles