Jump to content

Recommended Posts

Posted

Boas,

Surgiu-me uma problema que não consigo resolver. Eis a descrição do problema:

XML1 (short.xml):

<Employees>
<HumanResources.Employee>
<BusinessEntityID>1</BusinessEntityID>
<NationalIDNumber>295847284</NationalIDNumber>
<IDLogin>adventure-works\ken0</IDLogin>
<JobTitle>Chief Executive Officer</JobTitle>
<BirthDate>1959-03-02</BirthDate>
<MaritalStatus>S</MaritalStatus>
<Gender>M</Gender>
<HireDate>1999-02-15</HireDate>
<Address>Rua de Soutelo-Mouriz n100, 4580-596</Address>
<City>VN Famalicao</City>
</HumanResources.Employee>
<HumanResources.Employee>
<BusinessEntityID>2</BusinessEntityID>
<NationalIDNumber>295847285</NationalIDNumber>
<IDLogin>adventure-works\ken1</IDLogin>
<JobTitle>Chief Executive Officer</JobTitle>
<BirthDate>1959-03-02</BirthDate>
<MaritalStatus>S</MaritalStatus>
<Gender>M</Gender>
<HireDate>1999-02-15</HireDate>
<Address>Rua de Soutelo-Mouriz n100, 4580-596</Address>
<City>Vila Nova Famalicao</City>
</HumanResources.Employee>
<HumanResources.Employee>
<BusinessEntityID>3</BusinessEntityID>
<NationalIDNumber>295847286</NationalIDNumber>
<IDLogin>adventure-works\ken3</IDLogin>
<JobTitle>Chief Executive Officer</JobTitle>
<BirthDate>1959-03-02</BirthDate>
<MaritalStatus>S</MaritalStatus>
<Gender>M</Gender>
<HireDate>1999-02-15</HireDate>
<Address>Rua de Soutelo-Mouriz n100, 4580-596</Address>
<City>VNF</City>
</HumanResources.Employee>
</Employees>

XML2 (normalize.xml):

<root>
<elem>
<source>VNF</source>
<target>Vila Nova de Famalicão</target>
</elem>
<elem>
<source>Vila Nova Famalicao</source>
<target>Vila Nova de Famalicão</target>
</elem>

<elem>
<source>VN Famalicao</source>
<target>Vila Nova de Famalicão</target>
</elem>
</root>

XSLT :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="xml" select="document('short.xml')"></xsl:variable>
<xsl:variable name="norm" select="document('normalize.xml')"></xsl:variable>

<xsl:template match="node()|@*">
<xsl:for-each select="$xml/Employees/HumanResources.Employee">
<xsl:for-each select="$norm/root/elem">
<xsl:if test="$xml/Employees/HumanResources.Employee/City/text()=$norm/root/elem/source/text()">
<xsl:value-of select="$norm/root/elem/target/text()"/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Resumidamente, queria uniformizar o elemento City de cada Employee, que poderá tomar os vários valores Source, substituindo pelo Target.

Não sei se é possível, mas penso que faça sentido.

Agradeço toda a ajuda.

Obrigado

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.