tags:

views:

38

answers:

1

I have an XML file that is very long, but here is a shot excerpt.

<?xml version="1.0" encoding="UTF-8"?>
<dicom>
    <attr tag="00020000" vr="UL" len="4">190</attr>
    <attr tag="00020001" vr="OB" len="2">00\01</attr>
    <attr tag="00020002" vr="UI" len="30">1.2.840.10008.5.1.4.1.1.88.11</attr>
    <attr tag="00080090" vr="PN" len="14">Roberts^^^Dr.^</attr>
</dicom>

I also have an xslt file that is also very long, but here is an excerpt.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:output method="xml" indent="yes" media-type="text/xml-fo" encoding="UTF-8"/>
    <!-- the stylesheet processing entry point -->
    <xsl:template match="/">
        <xsl:apply-templates select="dicom"/>
    </xsl:template>

    <xsl:template match="dicom">
        TEST
        <xsl:variable name="name" select="attr[@tag='00080090']"/>
        <xsl:value-of select="$name"/>
    </xsl:template>
</xsl:stylesheet>

I have two questions. 1. When I apply the xml to the xslt, I don't get any output. After testing it appears that the dicom template is never even getting called. Why is this? 2. If I change the matching criteria for the dicom template from "dicom" to "/", then it does get called, but the variable is not being set correctly.

I know it won't produce valid XML, I'm just trying to figure out what's going on, and what's wrong with my understanding of xslt.

Thanks!!!

+3  A: 

Your sample works for me.

Please note that if the template matching / is simply doing an xsl:apply-templates on dicom you actually don't need it as there is already a built-in template that will be matched automatically doing exactly the same.

0xA3