We help IT Professionals succeed at work.

Need a transform. Relatively simple(?)

GessWurker
GessWurker asked
on
I need what I think is a relatively simple transform (but not for me!).  I just need to add the "match" elements. e.g.,

         <Match>
           <PropertyValues>
              <PropertyValue name="Record ID">14505</PropertyValue>
           </PropertyValues>
         </Match>
 

Here's my input (which lacks <Match>...):

<?xml version="1.0" encoding="UTF-8"?>
<Import>
  <ImportSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ImportFileFormat="Xml" MatchFoundAction="ReplaceRecord" MatchNotFoundAction="RejectRecord" UnrecognizedPropertyOption="Unspecified" ContentDetailExceptionOption="Unspecified" BubbleEventsOption="Unspecified" IsUpgradeOption="IsUpgrade" FileDispositionOption="Unspecified" BinaryFileDispositionOption="Unspecified" SkipRecordCount="0" MaximumRecordCount="0" UseSaxon="false">
    <SinkPath />
    <ExceptionFilePath />
    <AltBinariesPath />
    <TransformURL />
    <TransformFileWrapper />
    <LocalizablePropertyLocale>en-US</LocalizablePropertyLocale>
  </ImportSettings>
  <ContentTypes>
    <ContentType name="Staff Publications">
      <Records>
        <Record>
          <PropertyValues>
            <PropertyValue name="Record ID">13457</PropertyValue>
            <PropertyValue name="Author">Baldwin, David</PropertyValue>
            <PropertyValue name="Author">Grayson, Curt</PropertyValue>
            <PropertyValue name="Title">Influence: Gaining commitment, getting results</PropertyValue>
            <PropertyValue name="Source">Greensboro, NC: Center for Creative Leadership</PropertyValue>
            <PropertyValue name="Publication Number">CCL# 424</PropertyValue>
            <PropertyValue name="Publication Year" id="Publication_Year_10766">2004</PropertyValue>
            <PropertyValue name="Subject">Influence</PropertyValue>
            <PropertyValue name="Notes">Ideas into action guidebook</PropertyValue>
            <PropertyValue name="Notes">Includes: tables, self-guided worksheet, suggested reading</PropertyValue>
            <PropertyValue name="Full Text"/>
            <PropertyValue name="Entry Date">05/26/2004</PropertyValue>
            <PropertyValue name="PDF File">http://leadernet/departments/publications/Docs/CCL%20Press%20Digital%20Bookshelf/424.pdf</PropertyValue>
            <PropertyValue name="Abstract">This book includes an assessment too to help readers determine the influence tactics they currently use. Some tactics depend on logic, others appeal to emotions, and others are cooperative appeals.</PropertyValue>
            <PropertyValue name="Last Modified">7/25/2012 7:19:00 PM</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Driving Team Effort</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Managers|Influencing, Leadership, Power</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Brings Out the Best in People</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Managers|Selecting, Developing, Accepting People</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Managers|Inspiring commitment</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Function|Leading Change</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Motivating Others</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Influence Others</PropertyValue>
            <PropertyValue name="ContentItemLanguage" id="ContentItemLanguage" />
            <PropertyValue name="Active" id="Active">True</PropertyValue>
            <PropertyValue name="inmCreatedBy" id="inmCreatedBy">Admin</PropertyValue>
            <PropertyValue name="inmCommunity" id="inmCommunity" />
          </PropertyValues>
        </Record>
         <Record>
          <PropertyValues>
            <PropertyValue name="Record ID">14505</PropertyValue>
            <PropertyValue name="Author">Vader, Darth</PropertyValue>
            <PropertyValue name="Found In" id="Found_In_10762">Galaxy News</PropertyValue>
            <PropertyValue name="Title">The Force: Why it makes me rule</PropertyValue>
            <PropertyValue name="Source">Dark Side Inc</PropertyValue>
            <PropertyValue name="Publication Number">00000000</PropertyValue>
            <PropertyValue name="Publication Year" id="Publication_Year_10766">1970</PropertyValue>
            <PropertyValue name="Subject">High potentials</PropertyValue>
            <PropertyValue name="In Print" id="In_Print_10769">Yes?</PropertyValue>
            <PropertyValue name="Location" id="Location_10770">Archives</PropertyValue>
            <PropertyValue name="Notes">This is a really important document</PropertyValue>
            <PropertyValue name="Full Text" id="Full_Text_10773">Blah blah blah</PropertyValue>
            <PropertyValue name="Doc Import" id="Doc_Import_10774">How do you do this?</PropertyValue>
            <PropertyValue name="Entry Date">August 1, 2012</PropertyValue>
            <PropertyValue name="Abstract">Blah blah blah blah blah (shortened)</PropertyValue>
            <PropertyValue name="Type" id="Type_10780">Kit</PropertyValue>
            <PropertyValue name="External Link" id="External_Link_10782">http://www.weather.com/</PropertyValue>
            <PropertyValue name="Last Modified">8/1/2012 7:02:00 PM</PropertyValue>
            <PropertyValue name="Rating" id="Rating" UserName="admin" EntryDate="8/1/2012 7:02:00 PM">5.00</PropertyValue>
            <PropertyValue name="Voting" id="Voting" UserName="admin" EntryDate="8/1/2012 7:02:00 PM">1.00</PropertyValue>
            <PropertyValue name="Tags" id="Tags" UserName="admin" EntryDate="8/1/2012 5:45:00 PM">awesomeness, world domination, mind control</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Function|Leading Change|Fosters a climate of experimentation.</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Function|Create a Common Vision</PropertyValue>
            <PropertyValue name="ContentItemLanguage" id="ContentItemLanguage" />
            <PropertyValue name="Active" id="Active">True</PropertyValue>
            <PropertyValue name="inmCreatedBy" id="inmCreatedBy">admin</PropertyValue>
            <PropertyValue name="inmCommunity" id="inmCommunity" />
          </PropertyValues>
        </Record>
      </Records>
    </ContentType>
  </ContentTypes>
</Import>


Here's my desired output:

<?xml version="1.0" encoding="UTF-8"?>
<Import>
  <ImportSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ImportFileFormat="Xml" MatchFoundAction="ReplaceRecord" MatchNotFoundAction="RejectRecord" UnrecognizedPropertyOption="Unspecified" ContentDetailExceptionOption="Unspecified" BubbleEventsOption="Unspecified" IsUpgradeOption="IsUpgrade" FileDispositionOption="Unspecified" BinaryFileDispositionOption="Unspecified" SkipRecordCount="0" MaximumRecordCount="0" UseSaxon="false">
    <SinkPath />
    <ExceptionFilePath />
    <AltBinariesPath />
    <TransformURL />
    <TransformFileWrapper />
    <LocalizablePropertyLocale>en-US</LocalizablePropertyLocale>
  </ImportSettings>
  <ContentTypes>
    <ContentType name="Staff Publications">
      <Records>
        <Record>
         <Match>
           <PropertyValues>
              <PropertyValue name="Record ID">13457</PropertyValue>
           </PropertyValues>
         </Match>
          <PropertyValues>
            <PropertyValue name="Record ID">13457</PropertyValue>
            <PropertyValue name="Author">Baldwin, David</PropertyValue>
            <PropertyValue name="Author">Grayson, Curt</PropertyValue>
            <PropertyValue name="Title">Influence: Gaining commitment, getting results</PropertyValue>
            <PropertyValue name="Source">Greensboro, NC: Center for Creative Leadership</PropertyValue>
            <PropertyValue name="Publication Number">CCL# 424</PropertyValue>
            <PropertyValue name="Publication Year" id="Publication_Year_10766">2004</PropertyValue>
            <PropertyValue name="Subject">Influence</PropertyValue>
            <PropertyValue name="Notes">Ideas into action guidebook</PropertyValue>
            <PropertyValue name="Notes">Includes: tables, self-guided worksheet, suggested reading</PropertyValue>
            <PropertyValue name="Full Text"/>
            <PropertyValue name="Entry Date">05/26/2004</PropertyValue>
            <PropertyValue name="PDF File">http://leadernet/departments/publications/Docs/CCL%20Press%20Digital%20Bookshelf/424.pdf</PropertyValue>
            <PropertyValue name="Abstract">This book includes an assessment too to help readers determine the influence tactics they currently use. Some tactics depend on logic, others appeal to emotions, and others are cooperative appeals.</PropertyValue>
            <PropertyValue name="Last Modified">7/25/2012 7:19:00 PM</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Driving Team Effort</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Managers|Influencing, Leadership, Power</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Brings Out the Best in People</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Managers|Selecting, Developing, Accepting People</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Managers|Inspiring commitment</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Function|Leading Change</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Motivating Others</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Others|Influence Others</PropertyValue>
            <PropertyValue name="ContentItemLanguage" id="ContentItemLanguage" />
            <PropertyValue name="Active" id="Active">True</PropertyValue>
            <PropertyValue name="inmCreatedBy" id="inmCreatedBy">Admin</PropertyValue>
            <PropertyValue name="inmCommunity" id="inmCommunity" />
          </PropertyValues>
        </Record>
        <Record>
         <Match>
           <PropertyValues>
              <PropertyValue name="Record ID">14505</PropertyValue>
           </PropertyValues>
         </Match>
          <PropertyValues>
            <PropertyValue name="Record ID">14505</PropertyValue>
            <PropertyValue name="Author">Vader, Darth</PropertyValue>
            <PropertyValue name="Found In" id="Found_In_10762">Galaxy News</PropertyValue>
            <PropertyValue name="Title">The Force: Why it makes me rule</PropertyValue>
            <PropertyValue name="Source">Dark Side Inc</PropertyValue>
            <PropertyValue name="Publication Number">00000000</PropertyValue>
            <PropertyValue name="Publication Year" id="Publication_Year_10766">1970</PropertyValue>
            <PropertyValue name="Subject">High potentials</PropertyValue>
            <PropertyValue name="In Print" id="In_Print_10769">Yes?</PropertyValue>
            <PropertyValue name="Location" id="Location_10770">Archives</PropertyValue>
            <PropertyValue name="Notes">This is a really important document</PropertyValue>
            <PropertyValue name="Full Text" id="Full_Text_10773">Blah blah blah</PropertyValue>
            <PropertyValue name="Doc Import" id="Doc_Import_10774">How do you do this?</PropertyValue>
            <PropertyValue name="Entry Date">August 1, 2012</PropertyValue>
            <PropertyValue name="Abstract">Blah blah blah blah blah (shortened)</PropertyValue>
            <PropertyValue name="Type" id="Type_10780">Kit</PropertyValue>
            <PropertyValue name="External Link" id="External_Link_10782">http://www.weather.com/</PropertyValue>
            <PropertyValue name="Last Modified">8/1/2012 7:02:00 PM</PropertyValue>
            <PropertyValue name="Rating" id="Rating" UserName="admin" EntryDate="8/1/2012 7:02:00 PM">5.00</PropertyValue>
            <PropertyValue name="Voting" id="Voting" UserName="admin" EntryDate="8/1/2012 7:02:00 PM">1.00</PropertyValue>
            <PropertyValue name="Tags" id="Tags" UserName="admin" EntryDate="8/1/2012 5:45:00 PM">awesomeness, world domination, mind control</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Function|Leading Change|Fosters a climate of experimentation.</PropertyValue>
            <PropertyValue name="Category" id="Category">Competency|Competency Collection|Leading Function|Create a Common Vision</PropertyValue>
            <PropertyValue name="ContentItemLanguage" id="ContentItemLanguage" />
            <PropertyValue name="Active" id="Active">True</PropertyValue>
            <PropertyValue name="inmCreatedBy" id="inmCreatedBy">admin</PropertyValue>
            <PropertyValue name="inmCommunity" id="inmCommunity" />
          </PropertyValues>
        </Record>
      </Records>
    </ContentType>
  </ContentTypes>
</Import>
Comment
Watch Question

zc2
CERTIFIED EXPERT

Commented:
Please, give this code a try

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<xsl:apply-templates select="*"/>
	</xsl:template>

	<xsl:template match="*">
		<xsl:copy>
			<xsl:apply-templates select="@* | * | text() | comment()"/>
		</xsl:copy>
    </xsl:template>

	<xsl:template match="Record">
		<xsl:copy>
	         <Match>
	           <PropertyValues>
	              <PropertyValue name="Record ID"><xsl:value-of 
	              select="PropertyValues/PropertyValue[@name='Record ID']"/></PropertyValue>
	           </PropertyValues>
	         </Match>
			<xsl:apply-templates select="@* | * | text() | comment()"/>
		</xsl:copy>
    </xsl:template>
	
	<xsl:template match="text() | @* | comment()">
		<xsl:copy/>
    </xsl:template>

</xsl:stylesheet>

Open in new window

Information Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
here you go

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="node()">
        <xsl:if test="self::PropertyValues">
            <Match>
                <PropertyValues>
                    <xsl:copy-of select="PropertyValue[@name='Record ID']"/>
                </PropertyValues>
            </Match>
        </xsl:if>
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>    
</xsl:stylesheet>

Open in new window

Author

Commented:
Both submissions worked, but Gertone's got me closer to the desired output with a cleaner transform, I think. I'll split points. Cheers!

Author

Commented:
Ah. I guess splitting points isn't an option anymore? (Guess I've been out of the loop to long.) In any case, thanks to all!
Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
welcome

Explore More ContentExplore courses, solutions, and other research materials related to this topic.