Skip to main content
Participant
June 13, 2012
Question

XSLT Trouble

  • June 13, 2012
  • 1 reply
  • 628 views

Hi,

I am currently trying to use an xslt transform to select data out of one xml file and put it in another.  Now I have a little experience with xml, but am completely new to xslt.  Here is what I have so far.

Part of the XML File:

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

<metadatareport xmlns="http://www.callassoftware.com/ns/pdftoolbox/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.callassoftware.com/ns/pdftoolbox/1.0 metadatareport.xsd">

     <documents>

          <document>

               <metadata>
                    <metadatavalue property_id="xmpMM:TV_SONumber">000_199_SO</metadatavalue>
                    <metadatavalue property_id="xmpMM:TV_ArtworkApproval">Yes</metadatavalue>

XSLT File:

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

<!-- DWXMLSource="_00IRG_000_199_SO-IM_000_003_805_L-.xml" -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

  <xsl:template match="/">

    <xsl:element name="field-list">

     <xsl:element name="field">

         <xsl:element name="tag">SO Number</xsl:element>

            <xsl:element name="value"><xsl:value-of select="metadatareport/documents/document/metadata/metadatavalue[@property_id='xmpMM:TV_SONumber']"/></xsl:element>

        </xsl:element>

        <xsl:element name="field">

         <xsl:element name="tag">Artwork Approved</xsl:element>

            <xsl:element name="value"><xsl:value-of select="metadatareport/documents/document/metadata/metadatavalue[@property_id='xmpMM:TV_ArtworkApproval']"/></xsl:element>

        </xsl:element>

    </xsl:element>

  </xsl:template>

</xsl:stylesheet>

This is the output I am getting:

<?xml version="1.0" encoding="UTF-8"?>
<field-list>
  <field>
   <tag>SO Number</tag>
   <value/>
   </field>
   <field>
   <tag>Artwork Approved</tag>
   <value/>
  </field>
</field-list>

Now the output is what I want except that the value elements are blank.  I just cannot seem to pull the SO Number and Artwork Approval values from the original xml file no matter what I try.  Like I said I am very new to xslt, so I am completely at a loss for how to fix this.  So if anybody could help me figure out how to select those values from the xml file or give some advice on what I am doing wrong, it would be greatly appreciated.

Thanks

This topic has been closed for replies.

1 reply

Participant
June 13, 2012

This XSLT seems to work:

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

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">

          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

          <xsl:template match="/metadatareport">

                    <xsl:value-of select="documents/document/metadata/metadatavalue[@property_id='xmpMM:TV_ArtworkApproval']"/>

          </xsl:template>

</xsl:stylesheet>

The main difference being the template match parameter is "/metadatareport" instead of "/", and I removed the leading "metadatareport/" from the value-of select attribute.

jkamp89Author
Participant
June 13, 2012

Well I am getting values now, but it's not just the Artwork Approval and SO Number values.  There are about fifty <metadatavalue> elements, each with its own property_id and value.  I am now getting all fifty of those values displayed in the new xml file instead of just the two I need.