Reputation: 4741
This is hairdressing stuff! :)
What will it take to get those two node values out from the following XML doc?
<?xml version="1.0" encoding="utf-8"?>
<AlarmSummaryMessage
xmlns:cbrn="http://www.site.com/cbrn"
xmlns:nc="http://www.site.com/nc"
xmlns:scr="http://www.site.com/src"
xmlns="http://www.site.com/xmlns" xmlns:em="http://www.site.com/em">
<MessageContent detectionEventKindCode="encounter">
<AlarmingDevice>
<EncounterDeviceID>Raid-WTC</EncounterDeviceID>
<cbrn:EncounterDeviceID2>Raid-WTC</cbrn:EncounterDeviceID2>
</AlarmingDevice>
</MessageContent>
</AlarmSummaryMessage>
Using following XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
<xsl:template match="MessageContent">
<xsl:text>DEVICE: </xsl:text>
<xsl:value-of select="AlarmingDevice/EncounterDeviceID/text()"/>
</xsl:template>
<xsl:template match="AlarmSummaryMessage">
<xsl:apply-templates select="MessageContent" />
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Views: 120
Reputation: 4015
Because your XML elments belong to a namespace, you will have to mention that namespace in the XSLT - something like the following will get you started:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tns="http://www.site.com/xmlns"
xmlns:cbrn="http://www.site.com/cbrn">
<xsl:output method="text" indent="no"/>
<xsl:template match="tns:MessageContent" priority="2">
<xsl:text>DEVICE:
</xsl:text>
<xsl:value-of select="tns:AlarmingDevice/tns:EncounterDeviceID"/>
<xsl:text>; </xsl:text>
<xsl:value-of select="tns:AlarmingDevice/cbrn:EncounterDeviceID2"/>
</xsl:template>
<xsl:template match="/tns:AlarmSummaryMessage" priority="1">
<xsl:apply-templates select="tns:MessageContent" />
</xsl:template>
</xsl:stylesheet>
Please note the namespace definitions within the xsl:stylesheet tag and the prefixes in front of the node names.
Upvotes: 1
Reputation: 53
Unless I misunderstand your question, I believe that you are simply looking for the following:
<xsl:value-of select="/MessageContent/AlarmingDevice/EncounterDeviceID"/>
<xsl:value-of select="/MessageContent/AlarmingDevice/cbrn:EncounterDeviceID2"/>
Upvotes: 1